Skip to main content
Participant
Aug 10, 2019 7:20 PM UTC
Answered

SUMIF in PDF Form

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

try67
try67Correct answer
Community Expert
Aug 10, 2019 9:02 PM UTC

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;

9 replies

Participant
Apr 7, 2020 12:21 AM UTC

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 

Translate
Thom Parker
Community Expert
Community Expert
Apr 7, 2020 4:59 PM UTC

Have you checked the console window for errors?

Watch this console tutorial here:

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

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
Apr 9, 2020 3:20 PM UTC

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
try67
Community Expert
Community Expert
Aug 10, 2019 7:40 PM UTC

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

Translate
vmatos42Author
Participant
Aug 10, 2019 8:06 PM UTC

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.

Translate
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Aug 10, 2019 9:02 PM UTC

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