Skip to main content
Participant
August 10, 2019
Answered

SUMIF in PDF Form

  • August 10, 2019
  • 2 replies
  • 3147 views

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

Correct answer try67

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;

2 replies

Participant
April 7, 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

 

 

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

Thom Parker
Community Expert
Community Expert
April 7, 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 PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
April 9, 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]

try67
Community Expert
Community Expert
August 10, 2019

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

vmatos42Author
Participant
August 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.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 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;