Skip to main content
Participant
September 1, 2016
Answered

Populate expiry date field when digitally signed.

  • September 1, 2016
  • 1 reply
  • 1289 views

I am trying to get a text field to automatically populate when the form is digitally signed. The text field is an expiry date which needs to show the date 10 years less one day from time of signing. For example, if the form was signed today the Expiry Date text field should show August 31, 2026. I have been using the following JavaScript code in the Actions properties of the signature box:

// JavaScript code to add the date at signing time

    var currentTime = new Date()

    var month = currentTime.getMonth() + 1

    var day = currentTime.getDate()- 1

    var year = currentTime.getFullYear() + 10

    var signingTime = month +"/"+day+"/"+year

    var f = this.getField("ExpiryDate");

    f.value = signingTime;

This code had been working just fine, but obviously if the Date is the first of the month it will return a value of 0 for the day variable. I'm wondering if there is any way I can modify the script to prevent this error?

This topic has been closed for replies.
Correct answer try67

It's easier to make the adjustments to the Date object directly. Like this:

var d = new Date();

d.setFullYear(d.getFullYear()+10);

d.setDate(d.getDate()-1);

var signingTime = util.printd("mm/dd/yyyy", d);

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
September 1, 2016

It's easier to make the adjustments to the Date object directly. Like this:

var d = new Date();

d.setFullYear(d.getFullYear()+10);

d.setDate(d.getDate()-1);

var signingTime = util.printd("mm/dd/yyyy", d);

Participant
September 1, 2016

Hi try67,

I tried it but it still outputs the date as 9/0/2026 :/

try67
Community Expert
Community Expert
September 1, 2016

Can you post the full code you're using now?