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

Populate expiry date field when digitally signed.

New Here ,
Sep 01, 2016 Sep 01, 2016

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?

TOPICS
Acrobat SDK and JavaScript
1.2K
Translate
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

correct answers 1 Correct answer

Community Expert , Sep 01, 2016 Sep 01, 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);

Translate
Community Expert ,
Sep 01, 2016 Sep 01, 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);

Translate
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 ,
Sep 01, 2016 Sep 01, 2016

Hi try67,

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

Translate
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 ,
Sep 01, 2016 Sep 01, 2016

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

Translate
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 ,
Sep 01, 2016 Sep 01, 2016

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...

Translate
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 ,
Sep 01, 2016 Sep 01, 2016
LATEST

Ok never mind, I got it to work. Thank you so much for your help!

Translate
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