Skip to main content
Known Participant
July 10, 2022
Answered

How to calculate total hours based on hours worked in a specific role in Acrobat form

  • July 10, 2022
  • 1 reply
  • 2271 views

I have three field types I need to do a calculation on. I have 18 possible entries on a form that is basically a timesheet. User enters hours worked and chooses the service they performed from a drop-down. At the bottom of the form, there is a text box to display the total hours worked for that activity. There are 9 of these boxes, one for each service category. What I want to do is have the form calculate these totals. For example, John Smith did 4 hours on day 1 of the month doing Community Service. On Day 10 he also did Community Service. That would be two of the 18 services performed rows. There arw 18 rows that contain the Hours served and the type of service. This total would need to be added to the Community Service total box. There remain 16 rows that could be any of the other 8 service types.

To sum it up, I want to be able to have the one service type add up the total hours from the total hours fields in the two rows that are Community Service in this example. Keeping in mind this will need to be done for each service type that may appear in the form. We also have no way of knowing ahead of time what order entries will be made, as they take place on different dates.

This topic has been closed for replies.
Correct answer try67

to demonstrate the cells and info I want to calculate that I can't find an existing script that works that will accomplish this, after three days of searching. This should be simple, but I'm not a programmer. The 

The category list is ServiceHeading1-18. The hours worked is HoursServed1-18. The boxes for the total by service/task are labeled/named as shown.

 

Thanks for any help you can offer on this auto calculation scri[ting.


Here's an example of how to calculate the total time for Meetings, for example:

 

 

var total = 0;
for (var i=1; i<=18; i++) {
	if (this.getField("ServiceHeading"+i).valueAsString=="Mettings")
		total+=Number(this.getField("HoursServed"+i).valueAsString);
}
event.value = total;

 

1 reply

try67
Community Expert
Community Expert
July 10, 2022

This is possible, using a custom-made script. There are two steps here:

- Calculate the total time worked for each row.

- Add up those times depending on the Type of Service for all the rows.

There have been many discussions here on the former, including full code samples. I suggest trying to search the forum for "worksheet calculation" or something similar.

If the results are in numeric form (ie. 1.25, instead of 1:15) then the second step is pretty straight forward. You would just need a loop that checks the Type of Service value in each row and then adds them up to get a total. If they are in the latter form then it's a bit more complex, as you'll first need to convert those values to numbers, then add them up, then convert the result back to an HH:MM format.

Known Participant
July 12, 2022

 

Known Participant
July 12, 2022

Not sure what this image is supposed to say to me...


to demonstrate the cells and info I want to calculate that I can't find an existing script that works that will accomplish this, after three days of searching. This should be simple, but I'm not a programmer. The 

The category list is ServiceHeading1-18. The hours worked is HoursServed1-18. The boxes for the total by service/task are labeled/named as shown.

 

Thanks for any help you can offer on this auto calculation scri[ting.