You are viewing limited content. For full access, please sign in.

Question

Question

Calculate Default Value for Pay Period Ending Date

asked on September 2, 2016 Show version history

I'm wondering if there's a way to calculate a Form (version 10.1) date field based on the date the form is being filled out and a list of dates.  For instance, given today is 9/2/2016, based on the list of pay period ending dates (09/10/2016, 09/24/2016, 10/08/2016, 10/22/2016, etc.), it populates 9/10/2016 as the next pay period ending date.

In Excel, I can calculate the number of weeks since the first Pay Period Ending Date, roundup to the next integer, and multiply by 14.  (Also, Excel knows that this was a Leap Year.)

Any assistance would be appreciated! 

 

1 0

Replies

replied on September 2, 2016

The most efficient way would be with JavaScript in the Forms Layout. Use a set value with the id of the date field as the target, and use the current date as the input for a formula to choose the date.

This should get you pointed in the right direction:

https://answers.acrobatusers.com/auto-populating-pay-period-on-form-q285209.aspx

0 0
replied on September 2, 2016

Thank you for your response, Glen! 

I don't suppose you could tell me where those ID's get plugged in to that js?  My form date ID is q19, pay period date is q20.  (JavaScript is not something I have picked up on very well.) 

function getPayPeriod(theDate) {
    var janFirst = new Date(theDate.getFullYear(), 0, 1);
    // what day of the week is janFirst? 
    var theDay = janFirst.getDay();
    // what is the next Saturday? 
    var firstSaturday = new Date(janFirst);
    var numberOfDaysToAdd = 6 - theDay;
    firstSaturday.setDate(firstSaturday.getDate() + numberOfDaysToAdd); 

    return Math.floor(((theDate - firstSaturday) / 86400000)/14 + 1);
}
var theDateStr = this.getField("TheDate").valueAsString;
var theDate = util.scand("mm/dd/yyyy", theDateStr);
if (theDateStr != "" && theDate != null) {   
    event.value = getPayPeriod(theDate);
}
else {
    event.value = "";
}

Thank you! 

0 0
replied on September 2, 2016

You would need to modify the javascript to work with your form. If you look in the Javascript and CSS tab in the forms designer you'll see the ids, and there are setter and getter shortcuts to insert the code. 

http://www.w3schools.com/ is the best free resource for learning javascript. I'm afraid I'm not able to help much more than that.

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.