## Nesting a custom calculation into an IF Statement

New Here ,
Oct 16, 2018

Copied

Hi

I have 4 fields.

"Blank Check" is a Y/N dropdown

"Mark Up" is a list of percentages

"Check amount" is a free text field that only accepts numbers

"Billable Amount" multiplies "Check Amount" and "Markup" and adds that to the value entered into "check amount" for a total.

What I need to do is create a formula that automatically runs the same calculation, but adds \$1.00 to the total, to flag an amount to be adjusted later.

The formula I am using as of now is

CheckAmt * MarkUp + CheckAmt

And this is the formula I have tried

if(this.getField("BlankCheck").value="Yes")

event.value=("CheckAmt")+1

Any help would be appreciated.

Sorry about that, it should have been clear from your question, but I guess I saw too many instances of "check" and got pulled down the wrong path.

Now that I know what the correct behavior is, try this:

`if (this.getField("Dropdown13").value == "Yes") {     event.value = this.getField("CheckAmt").value + 1;}else {    event.value = this.getField("CheckAmt").value * this.getField("MarkUp").value + this.getField("CheckAmt").value;}`
TOPICS
Acrobat SDK and JavaScript, Windows

Views

168

Likes

Report

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

## Nesting a custom calculation into an IF Statement

New Here ,
Oct 16, 2018

Copied

Hi

I have 4 fields.

"Blank Check" is a Y/N dropdown

"Mark Up" is a list of percentages

"Check amount" is a free text field that only accepts numbers

"Billable Amount" multiplies "Check Amount" and "Markup" and adds that to the value entered into "check amount" for a total.

What I need to do is create a formula that automatically runs the same calculation, but adds \$1.00 to the total, to flag an amount to be adjusted later.

The formula I am using as of now is

CheckAmt * MarkUp + CheckAmt

And this is the formula I have tried

if(this.getField("BlankCheck").value="Yes")

event.value=("CheckAmt")+1

Any help would be appreciated.

Sorry about that, it should have been clear from your question, but I guess I saw too many instances of "check" and got pulled down the wrong path.

Now that I know what the correct behavior is, try this:

`if (this.getField("Dropdown13").value == "Yes") {     event.value = this.getField("CheckAmt").value + 1;}else {    event.value = this.getField("CheckAmt").value * this.getField("MarkUp").value + this.getField("CheckAmt").value;}`
TOPICS
Acrobat SDK and JavaScript, Windows

Views

169

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 16, 2018 0
12 Replies 12
New Here ,
Oct 16, 2018

Copied

Forgot to mention, the "Blank Check" field being selected "yes" needs to flag the amount to add \$1.00. If selected "no", it should run as normal. Thank you!

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 16, 2018 0
Most Valuable Participant ,
Oct 16, 2018

Copied

Second, you must compare using == not =, which causes disaster.

Third, you put the conditional statement (the thing to run if the condition is true) in braces { like this; }

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 16, 2018 0
Oct 16, 2018

Copied

I assume you are using the simplified field notation for your calculation. You will have to switch to a JavaScript calculation script. Your current calculation would look like this in JavaScript:

`event.value = this.getField("CheckAmt").value * this.getField("MarkUp").value + this.getField("CheckAmt").value;`

I assume that's pretty self explanatory.

There are different ways to add the \$1 if the checkbox is checked. To keep things simple and easy to follow, I would recommend something like this:

`var adjustment = 0; // the default is to not adjust the value;if (this.getField("BlankCheck").value != "Off") {    adjustment = 1;  // adjust by adding \$1 to the calculated value}event.value = this.getField("CheckAmt").value * this.getField("MarkUp").value + this.getField("CheckAmt").value + adjustment;`

I am testing for the checkbox to be "not set to 'Off'" - this is because you can actually override the checked value, but the deselected value will always be "Off".

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 16, 2018 0
New Here ,
Oct 17, 2018

Copied

OK, so I clearly have no explained myself well. I do not think this needs to be very complicated.

If Dropdown13 (Blank Check) is selected "Yes", I need CheckAmt * MarkUp + CheckAmt + \$1.00

If Dropdown13 (Blank Check) is selected "No", I need CheckAmt * MarkUp + CheckAmt

Here is what I tried

if(getField("Dropdown13")=="yes"){

event.value = CheckAmt * MarkUp + CheckAmt + 1;

} else{

event.value = CheckAmt * MarkUp + CheckAmt;

}

Go easy on me! Thank you so much.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 17, 2018 0
Oct 17, 2018

Copied

It looks like you are trying to mix JavaScript and simple field notation - this will not work. You have to create the whole script in JavaScript, which means that you cannot just use the field names to get the field values. Take a look at my script above for information about how to get the field value. If the dropdown is not called "Blank Check", you have to replace that with the actual field name (which, based on your last comment, seems to be "Dropdown13").

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 17, 2018 0
New Here ,
Oct 17, 2018

Copied

Thank you so much Karl! I really appreciate your patience.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 17, 2018 0
New Here ,
Oct 17, 2018

Copied

Karl,

One additional question. I just realized when Dropdown13 is selected "Yes", the billable amount does not need to factor in the MarkUp.

I tried to adjust your code as the following and it is now not taking the markup into account for either selection.

var adjustment = 0; // the default is to not adjust the value;

if (this.getField("Dropdown13").value != "No") {

event.value = this.getField("CheckAmt").value * this.getField("MarkUp").value + this.getField("CheckAmt").value + adjustment;

if (this.getField("Dropdown13").value != "Yes") {

Thank you

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 17, 2018 0
Oct 17, 2018

Copied

The unchecked value of a checkoff is _NOT_ "No", it is "Off".

What exactly do you need to calculate when the checkbox is not selected?

Given what you just posted, it sounds like the event value in this case would just the the "CheckAmt" value - is that correct? If that's the case, the following should work:

`if (this.getField("Dropdown13").value == "Off") {     event.value = this.getField("CheckAmt").value;}else {    event.value = this.getField("CheckAmt").value * this.getField("MarkUp").value + this.getField("CheckAmt").value + 1;}`

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 17, 2018 0
New Here ,
Oct 17, 2018

Copied

It is a dropdown with two selections - "Yes" and "No", not a checkbox.

When selected "Yes", I need it to calculate the CheckAmt + \$1.00

When selected "No", I need it to calculate the CheckAmt * MarkUp + CheckAmt but NOT add \$1.00

Thanks again!

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 17, 2018 0
Oct 17, 2018

Copied

Sorry about that, it should have been clear from your question, but I guess I saw too many instances of "check" and got pulled down the wrong path.

Now that I know what the correct behavior is, try this:

`if (this.getField("Dropdown13").value == "Yes") {     event.value = this.getField("CheckAmt").value + 1;}else {    event.value = this.getField("CheckAmt").value * this.getField("MarkUp").value + this.getField("CheckAmt").value;}`

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 17, 2018 1
New Here ,
Oct 17, 2018

Copied

That is exactly what I was trying to do! Thank you so much Karl, I truly appreciate it.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 17, 2018 0
LATEST
Oct 17, 2018