Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

calculate withholding using percentage and amount

Avatar

Level 1

i have a dynamic form with three decimal fields:

grossamount (grossamount)

withholding percentage (fwpercent)

withholding amount (fwamount)

i have the following scripts:

 

form1.#subform[0].fwpercent::calculate - (FormCalc, client)

fwamount/grossamount*100

 

form1.#subform[0].fwamount::calculate - (FormCalc, client)

grossamount*fwpercent/100

I want to be able to change either the amount and/or the percent and have it calculate the other as shown in the scripts. If I open the form and plug in 100 for gross amount, then 10 for percent, the script works correctly and 10 is then shown in w/h amount. If I then go to the fw amount field and change it to 20, the percentage field still shows 10. the results are the same if I do amount first, it will then change the percentage value but won't update amount if I then update percentage. It only will work for whatever I do first. Can I get the fields to always be dependent on eachother every time one of them is changed?

1 Accepted Solution

Avatar

Correct answer by
Level 1

changed to the scripts below and it works as expected:

 

form1.PaymentInfo.FederalWithholdingPercentage::exit - (JavaScript, client)

FederalWithholding.rawValue=GrossAmount.rawValue*FederalWithholdingPercentage.rawValue/100;

 

form1.PaymentInfo.FederalWithholding::exit - (JavaScript, client)

FederalWithholdingPercentage.rawValue=FederalWithholding.rawValue/GrossAmount.rawValue*100;

View solution in original post

1 Reply

Avatar

Correct answer by
Level 1

changed to the scripts below and it works as expected:

 

form1.PaymentInfo.FederalWithholdingPercentage::exit - (JavaScript, client)

FederalWithholding.rawValue=GrossAmount.rawValue*FederalWithholdingPercentage.rawValue/100;

 

form1.PaymentInfo.FederalWithholding::exit - (JavaScript, client)

FederalWithholdingPercentage.rawValue=FederalWithholding.rawValue/GrossAmount.rawValue*100;