Skip to main content
buddstud2006
Participating Frequently
May 28, 2019
Question

Field calculation with if statement - adding multiple fields

  • May 28, 2019
  • 1 reply
  • 413 views

I'm attempting to create a custom calculation script with an if statement, a check box, and other fields to be added.

My current code is below below: 

var cTX_CHKBOX = this.getField("TX_CHKBOX").value;

var nTOTAL_PREMIUM = this.getField("TOTAL_PREMIUM").value;

var nOUR_PREMIUM = this.getField("OUR_PREMIUM").value;

var nTOTAL_PREMIUM_UCC = this.getField("TOTAL_PREMIUM_UCC").value;

var nOUR_PREMIUM_UCC = this.getField("OUR_PREMIUM_UCC").value;

var nESCROW_FEE = this.getField("ESCROW_FEE").value;

var nCPL_FEE = this.getField("CPL_FEE").value;

var nFEDEX_FEE = this.getField("FEDEX_FEE").value;

var nSEARCH_FEE = this.getField("SEARCH_FEE").value;

var nRECD_FEE = this.getField("RECD_FEE").value;

var nTRANSFER_TAX = this.getField("TRANSFER_TAX").value;

var nTIEFF_FEE = this.getField("TIEFF_FEE").value;

var nMISC_CHARGE_FEE_I = this.getField("MISC_CHARGE_FEE_I").value;

var nMISC_CHARGE_FEE_II = this.getField("MISC_CHARGE_FEE_II").value;

var nADDL_FEE = this.getField("ADDL_FEE").value;

if ( cTX_CHKBOX == "Off" ) event.value = nOUR_PREMIUM + nOUR_PREMIUM_UCC + nESCROW_FEE + nCPL_FEE + nFEDEX_FEE + nSEARCH_FEE + nRECD_FEE + nTRANSFER_TAX + nTIEFF_FEE + nMISC_CHARGE_FEE_I + nMISC_CHARGE_FEE_II + nADDL_FEE;

else event.value = nTOTAL_PREMIUM + nTOTAL_PREMIUM_UCC + nESCROW_FEE + nCPL_FEE + nFEDEX_FEE + nSEARCH_FEE + nRECD_FEE + nTRANSFER_TAX + nTIEFF_FEE + nMISC_CHARGE_FEE_I + nMISC_CHARGE_FEE_II + nADDL_FEE;

Basically, the code works that if the box is not checked to add certain fields together, and if checked, to other certain fields together.

(note: the only fields that change between the two or nOUR_PREMIUM/nOUR_PREMIUM_UCC and nTOTAL_PREMIUM/nTOTAL_PREMIUM_UCC)

When I input this code, the calculation field does not sum at all, and stays zero regardless if the box is checked.

I've also tried the number variables with the Number(this.getField("X')value); syntax, and that didn't work either.

Thank you in advance for any help you can give!

Brett

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
May 28, 2019

The first thing you must always do when your code doesn't work is to check the JS Console (Ctrl+J) for error messages.

buddstud2006
Participating Frequently
May 29, 2019

Thank you!  I've never done a custom calculation script in Adobe and did not know of the JS Console.  I was able to find my error using this tool.

For anyone who is interested, I mislabeled a field name calling on its value ("Total Premium_UCC") was ("Total_Premium_UCC")

After this correction, the above code worked properly.

Thanks again!

Brett