Copy link to clipboard
Copied
I am new to calculating in PDF Forms and am fumbling throuth this. I have a sales sheet that our team uses to track outbound sales and inbound sales. Some of the sales are to new accounts. I am trying to figure out how to put the following into a script that will do what I want.
Goal: If the New column is not blank then the total should be reflected in the Amount field indicated below. If there are multiple "New" marked in the New column return the sum of these totals in the Amount Field.
I hope this makes sense. I have attached an example of the form.
Copy link to clipboard
Copied
Let's say the fields are named New1 to New20 and Total1 to Total20. You can then use this code as the custom calculation script of the Amount field:
var totalNew = 0;
for (var i=1; i<=20; i++) {
if (this.getField("New"+i).valueAsString!="Off")
totalNew+=Number(this.getField("Total"+i).valueAsString);
}
event.value = total;
(I assume the New fields are check-boxes, not text fields...)
Copy link to clipboard
Copied
Thank you for the reply. The fields are actually text fields not check boxes. Is there an adjustment that can be made to your code to make the text fields work in the calculation or should I cahnge them all to checkboxes?
Copy link to clipboard
Copied
Changing the field type is tricky. If you want you can simply change this part of the code:
this.getField("New"+i).valueAsString!="Off"
To:
this.getField("New"+i).valueAsString!=""
Copy link to clipboard
Copied
This article will explain how it works:
https://acrobatusers.com/tutorials/conditional-execution/