Copy link to clipboard
Copied
I'm trying to adapt code to my needs but am having problems with it.
I have checkbox fields with numbers as export values and trying to sum those values if checkboxes are checked, here is what I have:
var total = "";
for (var i=1; i<=5; i++) {
if (this.getField("C"+i).valueAsString!= "Off") total = this.getField("C"+i).value;
}
event.value = total;
Change the first line to:
var total = 0;
Copy link to clipboard
Copied
You don't need a script for this. At calculation use the option "Value is the sum of the following fields".
Copy link to clipboard
Copied
I can't do that because I have other calculations in the same field.
Copy link to clipboard
Copied
You're not adding up the values, but overwriting them.
Change this:
total = this.getField("C"+i).value;
To:
total += Number(this.getField("C"+i).valueAsString);
Copy link to clipboard
Copied
I tried that already but I'm getting value as string e.g. 100200300 instead of 600.
Copy link to clipboard
Copied
Change the first line to:
var total = 0;
Copy link to clipboard
Copied
Thank you, that worked.