Copy link to clipboard
Copied
I have a series of numbers that I need to add, they are in 9 fields. The page is a template, the first problem was getting it change the names of the fields to match the spawned page within the script. I solved that problem.
The current problem is that if one of the fields is blank, it does not read that field as a '0', it stops adding and combines the rest of the numbers as if they were text.
So, if the first 3 fields were 1,1,2 the result would be '4', however if they were 1,1, (blank),2 I would get '22'. It adds the first 2 numbers, then it hits the blank, then it will combine the numbers thereafter. 1,1,(blank),2,3,4 would be 2234, I want it to = 11
I need it to consider a blank field a zero so that it continues to add, the 'custom calculation script' is below, please help.
(function () {var f_name = event.target.name; var aName = f_name.split("."); var f_prefix = aName[0] + "." + aName[1];
event.value =
this.getField([f_prefix] + ".ADA A QTY").value
+
this.getField([f_prefix] + ".ADA B QTY").value
+
this.getField([f_prefix] + ".ADA C QTY").value
+
this.getField([f_prefix] + ".ADA D QTY").value
+
this.getField([f_prefix] + ".ADA E QTY").value
+
this.getField([f_prefix] + ".ADA F QTY").value
+
this.getField([f_prefix] + ".ADA G QTY").value
+
this.getField([f_prefix] + ".ADA H QTY").value
+
this.getField([f_prefix] + ".ADA I QTY").value
})();
You need to explicitly convert each value to a number. For example:
Number(this.getField(f_prefix + ".ADA A QTY").value)
I also removed the square brackets around f_prefix. They are not needed and can cause the script to fail.
Copy link to clipboard
Copied
You need to explicitly convert each value to a number. For example:
Number(this.getField(f_prefix + ".ADA A QTY").value)
I also removed the square brackets around f_prefix. They are not needed and can cause the script to fail.
Copy link to clipboard
Copied
That did the trick, thank you very much!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now