Skip to main content
smanne1888
Participating Frequently
October 16, 2018
Answered

Nesting a custom calculation into an IF Statement

  • October 16, 2018
  • 3 replies
  • 1074 views

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.

This topic has been closed for replies.
Correct answer Karl Heinz Kremer

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!


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;

}

3 replies

Karl Heinz  Kremer
Community Expert
Community Expert
October 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".

smanne1888
Participating Frequently
October 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.

Karl Heinz  Kremer
Community Expert
Community Expert
October 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").

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

smanne1888
Participating Frequently
October 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!