Copy link to clipboard
Copied
I am trying to set a calculated field where I want the equation to say " If the sum of the selected fields is greater than $500, then display $500, if not display sum of selected fields". I am not experience is JavaScipt and need assistance writing the script.
Copy link to clipboard
Copied
You can do it using this code as the custom calculation script of the total field:
var fieldsToAdd = ["Amount1", "Amount2", "Amount3"]; // replace with actual field names
var total = 0;
for (var i in fieldsToAdd) {
var v = Number(this.getField(fieldsToAdd[i]).valueAsString);
total+=v;
}
event.value = Math.min(500, v);