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

Nesting a custom calculation into an IF Statement

New Here ,
Oct 16, 2018 Oct 16, 2018

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.

TOPICS
Acrobat SDK and JavaScript , Windows
893
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

correct answers 1 Correct answer

Community Expert , Oct 17, 2018 Oct 17, 2018

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;

}

Translate
New Here ,
Oct 16, 2018 Oct 16, 2018

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!

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 ,
Oct 16, 2018 Oct 16, 2018

To start with, is the field called "Blank Check" or "BlankCheck"

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

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 ,
Oct 16, 2018 Oct 16, 2018

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".

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 ,
Oct 17, 2018 Oct 17, 2018

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.

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 ,
Oct 17, 2018 Oct 17, 2018

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").

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 ,
Oct 17, 2018 Oct 17, 2018

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

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 ,
Oct 17, 2018 Oct 17, 2018

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") { 

    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;

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

    adjustment = 0;  // adjust by adding $1 to the calculated value 

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


Thank you

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 ,
Oct 17, 2018 Oct 17, 2018

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;

}

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 ,
Oct 17, 2018 Oct 17, 2018

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!

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 ,
Oct 17, 2018 Oct 17, 2018

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;

}

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 ,
Oct 17, 2018 Oct 17, 2018

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

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 ,
Oct 17, 2018 Oct 17, 2018
LATEST

If this is something you have to do more often, you may want to look into learning JavaScript. It's not as complicated as it sounds Take a look here for some advice on free resources: Learning to Program JavaScript for Adobe Acrobat - KHKonsulting LLC

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