Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Multiple Conditions within If Statements

New Here ,
Nov 26, 2022 Nov 26, 2022

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!

 

form.pngexpand image

 

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";}

 

TOPICS
How to , JavaScript , PDF forms
2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Nov 27, 2022 Nov 27, 2022

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.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 27, 2022 Nov 27, 2022

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'"?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 27, 2022 Nov 27, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 30, 2022 Nov 30, 2022
LATEST

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines