Highlighted

## Custom Calculation Script If Then Statement

New Here ,
Nov 17, 2020

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.

TOPICS
How to, PDF forms

Views

58

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

## Custom Calculation Script If Then Statement

New Here ,
Nov 17, 2020

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.

TOPICS
How to, PDF forms

Views

59

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 17, 2020 0
4 Replies 4
Most Valuable Participant ,
Nov 17, 2020

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...)

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 17, 2020 0
New Here ,
Nov 17, 2020

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?

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 17, 2020 0
LATEST
Most Valuable Participant ,
Nov 17, 2020

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!=""

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 17, 2020 0
Nov 17, 2020

Copied

https://acrobatusers.com/tutorials/conditional-execution/

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 17, 2020 0
Resources