Skip to main content
Participant
January 9, 2020
Question

Check sum of previous fields, then prompt

  • January 9, 2020
  • 1 reply
  • 932 views

Hello all! I'm hoping this is a fairly easy task. I'm fairly new to Acrobat and using JavaScript, but I've managed to get pretty far just from "Googling" for my answers. I'm not quite sure how to word this one, so, I'm turning to you guys for help. Here's the scenario...

 

I'm creating a fillable PDF, to be used as a timesheet. This document will allow employees to document their hours worked daily (or vacation time taken, comp time taken, etc.). I have several columns, but the three most important ones for this are "Hours worked, Regular OT, and Comp OT". 

 

In our department, employees don't hit overtime until they've worked 43 hours. Once they hit 43 hours, and time over that can be taken as Regular OT (paid to them at 1.5 time), or Comp OT (added to their compensatory time bank at a rate of 1.5).

 

Here's what I want the form to do, if possible. As an employee is entering their daily hours, I want the form to calculate the hours from the previous days, and include the current day. If their hours are over 43, I want the form to prompt the user, asking them if they'd like the overage of hours to go into the Regular OT column or the Comp OT column.

 

Thanks in advance!

 

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
January 9, 2020

So you didn't mention the most difficult part of this process, which is what happens after the user decides where the OT hours go. Is the excess automatically pushed off into the selected column? 

 

Creating the solution as you've discribed requires some advanced scripting skills. A much easier solution  is to put radio buttons over each column (Regular OT and Comp OT). The user then selects where the extra hours go.

 

 

 

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
JSLcpd157Author
Participant
January 9, 2020

Thank you for the reply! Yes, the excess amount would be put into the column that the user decides.

 

I assumed it was probably a fairly intricate script but, was hoping maybe someone had done something similar and might have the script they used on hand.

 

So, if I were to use the radio buttons, would that then force any amount over 43 (in the regular time column) into the other selected column? I'm trying to "dummy proof" this thing! lol

Thom Parker
Community Expert
Community Expert
January 10, 2020

The answer is, it's whatever you design the form and script to do. You have a wide range of possibilities.  If there are multiple lines, then you could have radio button on each line, or they could be at the top of the colum and used for every line.  I don't know how the fields are named on this form, but say they are

 

For the hours fields on the first Row:  "Row1.HoursRegOT" and "Row1.HoursCompOT"   

and the radio button is named: "Row1.OTSelect" with export values of "Reg" and "Comp"

 

Then the calculation on the "HoursWorked" field would include this code at the end of the calculation script:

 

if(event.value > 43)

{

      var overHours = 43 - event.value;

      if(this.getField("Row1.OTSelect").value == "Comp")

           this.getField("Row1.HoursCompOT").value = overHours;

      else

           this.getField("Row1.HoursRegOT").value = overHours;

}

 

Also, if there are multiple lines, I would make the calculation a document level function, and generate the field names so it would work for every line. 

 

You can find out everything you ever wanted to know about PDF form calculations here:

https://www.pdfscripting.com/public/Calculating-field-values-and-more.cfm 

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