Check sum of previous fields, then prompt

Jan 09, 2020

Copy link to clipboard

Copied

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!

 

TOPICS
Acrobat SDK and JavaScript, How to, PDF forms

Views

57

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Check sum of previous fields, then prompt

Jan 09, 2020

Copy link to clipboard

Copied

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!

 

TOPICS
Acrobat SDK and JavaScript, How to, PDF forms

Views

58

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jan 09, 2020 0
Adobe Community Professional ,
Jan 09, 2020

Copy link to clipboard

Copied

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.

 

 

 

 

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 09, 2020 0
Jan 09, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 09, 2020 0
Adobe Community Professional ,
Jan 09, 2020

Copy link to clipboard

Copied

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 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 09, 2020 0
Jan 10, 2020

Copy link to clipboard

Copied

Thanks!! I'll try that and see what I can accomplish. 

 

Yeah, I have checked out the pdfscripting website but, $149 is a little steep for a guy that will most likely rarely use JS for anything else. I have been using codeademy to try and learn some coding though!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 10, 2020 0
Jan 10, 2020

Copy link to clipboard

Copied

Also, if you could recommend one book to a "noob," to start learning JavaScript, what would it be?

 

I have limited coding experience but, I pick up on stuff fairly fast by looking at examples. 


Thanks!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 10, 2020 0
Adobe Community Professional ,
Jan 14, 2020

Copy link to clipboard

Copied

Get the O'Reilly book

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 14, 2020 0