Copy link to clipboard
Copied
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?
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);
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
Hi try67,
I tried it but it still outputs the date as 9/0/2026 😕
Copy link to clipboard
Copied
Can you post the full code you're using now?
Copy link to clipboard
Copied
Ok, sorry it was outputting 9/0/2026 because I hadn't deleted the old code in the signature box. Duh. But the date field doesn't seem to be populating when signed. Am I doing something wrong? I put the code you posted above in the custom validation script and in the custom calculation script and neither output the date value when the document is signed...
Copy link to clipboard
Copied
Ok never mind, I got it to work. Thank you so much for your help!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now