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

Creating a Custom Calculation Script in Adobe Acrobat

Community Beginner ,
Jun 01, 2018 Jun 01, 2018

Copy link to clipboard

Copied

Hi! I don't have any experience with script, but I think that I need to create a custom calculation script in my Adobe Acrobat form.

I have created a budget form and simply want to be able to enter expenses and have them automatically add up the running total. I'm trying to figure out a way to code this in the calculation area easily, without needing to write new code for each box.

So, for example, the form looks like this:

Date     Description     Category     Amount     Balance

4/23     Chipotle             Food            $25          $25

4/25     Starbucks          Food            $10          $35

4/27     Target                Supplies      $100        $135

I want the form to be able to automatically calculate that the balance is 35 when I add in the 10 for Starbucks, then 135 when I enter 100 for Target, etc. From looking it up in the past, I used the following for some similar calculations:

// Obtain the value from the first field

var v1 = getField("balance1").value;

// Obtain the value from the second field

var v2 = getField("amount2").value;

// Set this field value equal to the sum

event.value = v1 + v2;

When balance1 is the $25 and amount2 is the $10.

Is there a way I can change this formula to be able to use it for every balance field without needing to edit the formula in each one separately?

Thank you for your assistance!!

kristy

TOPICS
PDF forms

Views

55.2K

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

correct answers 1 Correct answer

Community Expert , Jun 02, 2018 Jun 02, 2018

OK, then this is the doc-level script you can use (insert it under Tools - JavaScripts - Document JavaScripts):

function calcBalance() {

    var rowNumber = Number(event.target.name.replace("balance", ""));

    var amount = Number(this.getField("amount"+rowNumber).valueAsString);

    if (amount==0) event.value = "";

    else {

        var prevBalance = 0;

        if (rowNumber!=1) prevBalance = Number(this.getField("balance"+(rowNumber-1)).valueAsString);

        event.value = amount+prevBalance;

    }

}

A

...

Votes

Translate

Translate
New Here ,
Mar 08, 2024 Mar 08, 2024

Copy link to clipboard

Copied

I need help. I need to know the code to calculate the Freight=Labels &Tags + Valves & Components (0.07)

AliBunn0430_1-1709928439093.png

 

 

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 ,
Mar 08, 2024 Mar 08, 2024

Copy link to clipboard

Copied

Do you mean: (Labels &Tags + Valves & Components) * (0.07) ?

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 ,
Mar 08, 2024 Mar 08, 2024

Copy link to clipboard

Copied

Yes, but I need that total to go to the fright column. If that makes sense. 

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 ,
Mar 08, 2024 Mar 08, 2024

Copy link to clipboard

Copied

You can use this code as that field's custom calculation script, then, just make sure the field names are spelled EXACTLY as they are in your file:

 

event.value = (Number(this.getField("Labels &Tags").valueAsString) + Number(this.getField("Valves & Components").valueAsString)) * 0.07;

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 ,
Mar 08, 2024 Mar 08, 2024

Copy link to clipboard

Copied

Excalent first reply, so you could say this is a probllem of scope_

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 ,
Sep 12, 2024 Sep 12, 2024

Copy link to clipboard

Copied

LATEST

stephanie_2694_1-1726168128137.png

 

Looking for some help. I am trying to find a calculation to put into Adobe, where I multiple the rank*weight of each row, then the priority score is the sum of it all.

 

Bonus: I am also looking to see if I can add a field under the Number Priority Score that states the word equivalent (So if the score is under 15, it will say "Good," between 15 and 22 "Excellent",and 23 and above "Outstanding"

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