Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

Apply Script to multiple fields

Avatar

Not applicable
I have a form with multiple fields that will contribute to a total. Is there a way to have script apply to multiple fields that will auto update the totals, instead of scripting a separate exit event for each field.



Thank you
2 Replies

Avatar

Not applicable
Create a Script Object. In that object, you can have a function like this:

function addMyFields() // add values in the fields

{

var number1 = field1.rawValue;

var number2 = field2.rawValue; // and so on



var sumOp = number1 + number2; // + number3 + .... and so on



totalField.rawValue = sumOp; // display sum in total field

}



Paste the following code in the exit event of each field:

ScriptObjectName.addMyFields();



Let me know if it works for you.

Avatar

Level 10
Or put your code on the Calculate event and as each field is changed the Total calculate event wil fire because there is a dependency between each field mentioned in the calc.