• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Custom Calculation Script If Then Statement

New Here ,
Nov 17, 2020 Nov 17, 2020

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.Example Spreadsheet.JPG

TOPICS
How to , PDF forms

Views

480

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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

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?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

This article will explain how it works:

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

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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