Copy link to clipboard
Copied
Hello!
I am running into issues and I can't seem to figure out why.
I'll try to write this simply... I am working on a paperwork package for a dealership to handle multiple vehicles sold at once. I have a couple line items that are divided evenly amongst all vehicles sold. If it is NOT able to be divided evenly, the remainder is calculated and added or deducted from the first vehicle sold. That is all working just fine. My problem is here... If the item is not divided evenly, a warning icon appears next to the line. This is the function I have written:
function warning(TotalField,PerField)
{
var PerName = event.target.name
var PerRounded = round(PerField,2);
var Count = this.getField("SOLD_COUNT").value;
var Offset = PerRounded * Count;
if ((Offset == TotalField) || (Offset == 0))
this.getField("WARNING_" + PerName).display = display.hidden
else
this.getField("WARNING_" + PerName).display = display.visible
}
The function seems to be working backwards. I want the icon to appear ONLY when Offset does not equal TotalField, but it appears when they are equal and disappears when they are not.
Any ideas??
Copy link to clipboard
Copied
From what context are you calling this function, and what values are you supplying to it as its parameters?
Copy link to clipboard
Copied
Here is some more info:
I have a line item applied to each vehicle called "PAYOFF_PER". This is calculated by taking the field "TOTAL_PAYOFF" and dividing it by the number of vehicles sold ("SOLD_COUNT").
Let's say TOTAL_PAYOFF is $5,000.00 and I'm selling 3 vehicles, making PAYOFF_PER 1,666.67 (rounded up). As 1,666.67 * 3 = 5,000.01, I want to alert the user here that the first vehicle will reflect a 1 cent deduction on the Payoff line.
The function in question is called from a validation script of PAYOFF_PER:
var total = this.getField("TOTAL_PAYOFF").value; // in this example: $5,000
var per = this.getField("PAYOFF_PER").value; // in this example: $1,666.6666666666(repeating)
warning(total,per);
Now the function (document level script) which *should* display button ("WARNING_PAYOFF_PER").
function warning(TotalField,PerField)
{
var PerName = event.target.name // in this example: PAYOFF_PER
var PerRounded = round(PerField,2); // in this example: 1,666.67
var Count = this.getField("SOLD_COUNT").value; // in this example: 3
var Offset = PerRounded * Count; // in this example: 5,000.01
if ((Offset == TotalField) || (Offset == 0)) // in this example: TotalField = 5,000.00, Offset = 5,000.01
this.getField("WARNING_" + PerName).display = display.hidden
else
this.getField("WARNING_" + PerName).display = display.visible
}
I want the button to appear only when TotalField does not equal Offset. If the are equal, or if there is nothing entered it should be hidden. For some reason I am getting the opposite.
Thanks again!
Copy link to clipboard
Copied
What's the code for the round function? Can you share the file, or post the full code, please?
Copy link to clipboard
Copied
Here is the code for the round function- I didn't write it, found it on a blog somewhere and it seemed to do the trick.
function round(value, decimals) {
return Number(Math.round(value+'e'+decimals)+'e-'+decimals);
}
Copy link to clipboard
Copied
I tested the code using the values you specified and it worked correctly (ie, the final result was that the field was shown)... Could you share the file in question?
Copy link to clipboard
Copied
By the way, if you're calling the code from the validation event of "PAYOFF_PER" then replace this line:
var per = this.getField("PAYOFF_PER").value;
With:
var per = event.value;
Copy link to clipboard
Copied
Great idea! Thank you! I can certainly send over the file, but I would prefer to do so privately if possible. Could you message me your email address?
Copy link to clipboard
Copied
I sent you a PM.