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

How to insert tomorrow's date in pdf.

New Here ,
Jan 16, 2022 Jan 16, 2022

Copy link to clipboard

Copied

I have a pdf that when it is opened I want dates to be auto-populated for printing purposes.  I've researched and can only make it partially work.  The only success I've had is by editing my pdf and creating my text fields and formatting them for my date format (mm-dd-yy).  Then to go to my page layout and open page properties, click on actions, and add an action that triggers on Page Open to run a javascript command.  The only command I'm getting to work is the following:

 

var f = this.getField("Sunday");
f.value = util.printd("mm-dd-yy", new Date());

 

This correctly and automatically populates my date field but only for the day I do it.  I'm trying to make the dates work for future dates also, such as tomorrow.  It appears the main javascript function is to use a getDate() command and do +1 for tomorrow but I can not get it to do this.  I've searched for different variations of adding tomorrow to the form and none of them appear to work or at least won't populate their fields upon opening my document.  IF anyone can offer any help I'd appreciate it.

 

TOPICS
Edit and convert PDFs , JavaScript , PDF forms

Views

1.8K

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
2 ACCEPTED SOLUTIONS
Community Expert ,
Jan 16, 2022 Jan 16, 2022

Copy link to clipboard

Copied

To populate date on opening you can use document level javascript (while in prepare form tool click on 'More' and select 'Document JavaScript' or press SHIFT+D ) and use something like this:

var days = util.scand("mm-dd-yy", new Date())
days.setDate(days.getDate() +1);
this.getField("Day").value = util.printd("mm-dd-yy", days);

Just change field name to your actual field name.

View solution in original post

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 Beginner ,
Oct 18, 2023 Oct 18, 2023

Copy link to clipboard

Copied

Is there a way upon opening that the 1st date not to change?  I need Monday's date to stay the same when form is reopened, but Tue-Sun to change +1.

Lynn324121208h83_0-1697645805697.png

 

View solution in original post

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 16, 2022 Jan 16, 2022

Copy link to clipboard

Copied

To populate date on opening you can use document level javascript (while in prepare form tool click on 'More' and select 'Document JavaScript' or press SHIFT+D ) and use something like this:

var days = util.scand("mm-dd-yy", new Date())
days.setDate(days.getDate() +1);
this.getField("Day").value = util.printd("mm-dd-yy", days);

Just change field name to your actual field name.

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 16, 2022 Jan 16, 2022

Copy link to clipboard

Copied

There's no need to use scand to create a new Date object for the current day. You can just use it directly.

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 Beginner ,
Oct 18, 2023 Oct 18, 2023

Copy link to clipboard

Copied

Is there a way upon opening that the 1st date not to change?  I need Monday's date to stay the same when form is reopened, but Tue-Sun to change +1.

Lynn324121208h83_0-1697645805697.png

 

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 ,
Oct 18, 2023 Oct 18, 2023

Copy link to clipboard

Copied

You can add this:

if(this.getField("Day").value == ""){

//put script here

}

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 Beginner ,
Oct 18, 2023 Oct 18, 2023

Copy link to clipboard

Copied

Updated and I'll have to wait til tomorrow. Thanks for your quick reply!

 

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 Beginner ,
Oct 20, 2023 Oct 20, 2023

Copy link to clipboard

Copied

LATEST

It worked!!!! 

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