• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Check sum of previous fields, then prompt

New Here ,
Jan 09, 2020 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

Views

435

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
community guidelines
Community Expert ,
Jan 09, 2020 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.

 

 

 

 

 

 

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

Votes

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
community guidelines
New Here ,
Jan 09, 2020 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

Votes

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
community guidelines
Community Expert ,
Jan 09, 2020 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 

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

Votes

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
community guidelines
New Here ,
Jan 10, 2020 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!

Votes

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
community guidelines
New Here ,
Jan 10, 2020 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!

Votes

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
community guidelines
Community Expert ,
Jan 14, 2020 Jan 14, 2020

Copy link to clipboard

Copied

LATEST

Get the O'Reilly book

 

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

Votes

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
community guidelines