Copy link to clipboard
Copied
I want to have the form automatically calculate/format the last row line based on fields labeled 1 and 2. It requires mutliple if statements with multiple conditions inside. I'm not sure if that's actually possible or not, but any help would be appreciated!
Below are issues I'm stuck on for fields 3 and 4. The table consists of the conditions with the desired result. The current script is underneath that.
For 3:
The number value entered in the targeted field doesn't change with any of the conditions.
Conditions | Result |
Reason Code = “INV - Customer Inventory Return” | Black/Helvetica |
Reason Code = “INV – Customer Inventory Return” Waived box is checked | 0% Black/Helvetica |
Otherwise | 0% ["RGB", 0.75, 0.75, 0.75]/Helvetica Oblique |
var RC = this.getField("Reason Code").value;
var cb = this.getField("WaivedButton").valueAsString;
if(cb == "On" && RC == "INV - Customer Inventory Return")
{event.value = '0';
event.target.textColor = color.black;
event.target.textFont = "Helvetica";}
else if(RC == "INV - Customer Inventory Return")
{event.target.textColor = color.black;
event.target.textFont = "Helvetica";}
else {event.target.textColor = ["RGB", 0.75, 0.75, 0.75];
event.target.textFont = "Helvetica-Oblique";}
For 4:
There's a hidden field that calculates the subtotal based on the other lines' total. When the waived box is checked the targeted field sets the text to match the last condition instead of the previous.
Conditions | Result |
Reason Code = “INV – Customer Inventory Return” Waived box not checked | = -(Subtotal x Percentage) Black/Helvetica |
Reason Code = “INV – Customer Inventory Return” Waived box checked | $0 Black/Helvetica |
Otherwise | $0 ["RGB", 0.75, 0.75, 0.75]/Helvetica Oblique |
var RC = this.getField("Reason Code").value;
var Sub = this.getField("Subtotal").value;
var Per = this.getField("Percentage").value;
var cb = this.getField("WaivedButton").valueAsString;
if((RC == "INV - Customer Inventory Return") && (cb == "Off"))
{event.value = -(Sub*Per);
event.target.textColor = color.black;
event.target.textFont = "Helvetica";}
else if((RC == "INV - Customer Inventory Return") && (cb == "On"))
{event.value = '0';
event.target.textColor = color.black;
event.target.textFont = "Helvetica";}
else {event.value = '0';
event.target.textColor = ["RGB", 0.75, 0.75, 0.75];
event.target.textFont = "Helvetica-Oblique";}
Copy link to clipboard
Copied
Did you set the Export Value of the check-box to "On" yourself? Because if you didn't, the value that's normally used is "Yes" (while the value for an unchecked field is always "Off"...). You can change it to "On", but don't assume that's the default state.
Copy link to clipboard
Copied
1. With this code, you've told us what you want to happen, but what actually does happen? Please be exact?
2. What messages appear in the JavaScript console?
3. Where exactly is each piece of code? For example, "the mouse down event of the field I called '3'"?
Copy link to clipboard
Copied
Did you set the Export Value of the check-box to "On" yourself? Because if you didn't, the value that's normally used is "Yes" (while the value for an unchecked field is always "Off"...). You can change it to "On", but don't assume that's the default state.
Copy link to clipboard
Copied
That worked like a charm once I changed the script to reflect "Yes". I'm self-taught and it was my first time using the custom calculation script option. Hadn't registered something so simple as the export value was the issue. Thank you for the help!

