Copy link to clipboard
Copied
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

Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
Sure. What are the names of the fields involved, though?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
wow thanks so much. worked perfectly
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Have you checked the console window for errors?
Watch this console tutorial here:
https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro
Copy link to clipboard
Copied
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]
Copy link to clipboard
Copied
Please contact me through the membership site and I'll see what I can do to get you on the right track.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more