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

SUMIF in PDF Form

New Here ,
Aug 10, 2019 Aug 10, 2019

I'm trying to create an expense reimbursement form that auto calculates amount subtotals based on the selection of expense types. Essentially, I want to have all Travel go into one subtotal field, all lodging to go in another, all per diem in another, etc. Is there a way to perform a SUMIF function in a PDF that will distribute those expense amounts by expense type? Thanks

form sample.png

TOPICS
PDF forms
3.2K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Aug 10, 2019 Aug 10, 2019

OK, then you can use something like this as the custom calculation script of "Traveltot":

var total = 0;

for (var i=0; i<=14; i++) {

    if (this.getField("Drop1."+i).valueAsString=="Travel") total+=Number(this.getField("Amount1."+i).valueAsString);

}

event.value = total;

View solution in original post

Translate
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 ,
Aug 10, 2019 Aug 10, 2019

Sure. What are the names of the fields involved, though?

Translate
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 ,
Aug 10, 2019 Aug 10, 2019

My bad sorry about that. Each field is using the same name or shortened of the column name. When I duplicated each row, Adobe automatically changed each one to add 1.1, 1.2, 1.3, etc.field samples.png

Translate
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 ,
Aug 10, 2019 Aug 10, 2019

OK, then you can use something like this as the custom calculation script of "Traveltot":

var total = 0;

for (var i=0; i<=14; i++) {

    if (this.getField("Drop1."+i).valueAsString=="Travel") total+=Number(this.getField("Amount1."+i).valueAsString);

}

event.value = total;

Translate
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 ,
Aug 10, 2019 Aug 10, 2019

wow thanks so much. worked perfectly

Translate
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 Beginner ,
Oct 17, 2025 Oct 17, 2025
LATEST

Hi Try67,

How would the formula below change, if instead of looking for the fixed string "travel" it would look at another field where I could enter whatever string I want it to calculate in that box?

JayNH_0-1760736680869.png

 

Translate
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 Beginner ,
Apr 06, 2020 Apr 06, 2020

try67

I want to use your script for a timesheet application. I am a beginner so I have been watching videos, googleing, etc. 

I recreated your expense report application so I could learn. I am missing something that I am hoping you can point me in the correct direction.

I have placed your calculation as a javascript under actions as well as a custom calculation script under calculate. As a test I created TotalCheck to at least get a calculation of somesort going. I hope either the script printout or my file are usable for you.

Thank you, Mari

 

mamoore_0-1586218568997.pngmamoore_1-1586218613593.png

 

https://drive.google.com/drive/u/0/folders/12IS40chnQ4GJrbuFepMh5YBb1h4sezNO 

Translate
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 ,
Apr 07, 2020 Apr 07, 2020

Have you checked the console window for errors?

Watch this console tutorial here:

https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro

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

Translate
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 Beginner ,
Apr 09, 2020 Apr 09, 2020

Thom
Thank you for reaching out. I am actually a customer of yours. I have been
jumping around the videos and decided it is best if I start with the first
one and go thru them all.

Then i'll revisit my task.

Mari

 

[Private info removed]

Translate
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 ,
Apr 09, 2020 Apr 09, 2020

Please contact me through the membership site and I'll see what I can do to get you on the right track.

 

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

Translate
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