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

Auto populate dates.

New Here ,
Feb 26, 2018 Feb 26, 2018

Copy link to clipboard

Copied

I have a time sheet that I have turned into a form and I would like to make the start date of the week  auto populate the rest of the dates. Is there a way to do this? Thanks for the help.

Capture.PNG

TOPICS
Acrobat SDK and JavaScript , Windows

Views

461

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 ,
Feb 26, 2018 Feb 26, 2018

Copy link to clipboard

Copied

Yes, you can, with a script.  This question comes around quite often and I know that solutions have been provided. Here are the results of a quick search on these forums:

https://forums.adobe.com/search.jspa?q=auto%20dates

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
New Here ,
Feb 26, 2018 Feb 26, 2018

Copy link to clipboard

Copied

Thanks for the info. It looks like all of these change the date every time you open it. I need to input the date in a field and then have it populate the rest of the dates from there. Also if i do get this to work will it work on an IOS Device?

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 ,
Feb 26, 2018 Feb 26, 2018

Copy link to clipboard

Copied

Before you decide on which script to use, verify that any code conforms to what is supported on iOS. You can find that documentation here...

JavaScript for Acrobat Reader Mobile API Reference (iOS)

For example, several of the scripts referenced in that list use the field property "valueAsString" which is no supported on Adobe Reader for iOS.

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 ,
Feb 26, 2018 Feb 26, 2018

Copy link to clipboard

Copied

In the search link I posted above there were several different threads with different solutions. The important bit is find code that calculates consecutive dates the way you want them. That code can be applied to a form in many different ways.

For you the easiest, and most workable solution (across platforms) is to have a single calculation script that finds all the dates and populates the other date fields. A good choice is the first field

Here's some example code, it assumes the first date in the table is named StartDate, an the following date fields are named "Date1" thru "Date6".

var startDate = this.getField("StartDate").value;

if (dtStart!="")

{

    var dtWkDay = util.scand("mm/dd/yyyy", dtStart);

     for(var i=1;i<7;i++)

     {

         this.getFiel("Date"+i).value =  util.printd("mm/dd/yyyy",dtWkDay.setDate(dtWkDay.getDate()+1);)

      }

}

However, as Joel has pointed out, you have a problem with Mobil PDF viewers because none of them provide anything close to the complete Acrobat JS model.  You should test on both the Acrobat mobile Reader and PDF Expert from Readdle, which is the best IOS PDF viewer

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
New Here ,
Mar 01, 2018 Mar 01, 2018

Copy link to clipboard

Copied

Thom,     

Thank you for all the help I have tried to put the code you supplied in but i keep getting this error:

Capture.PNG

any help is greatly appreciated.

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 ,
Mar 01, 2018 Mar 01, 2018

Copy link to clipboard

Copied

LATEST

Replace line #7 of the code above with this:

this.getField("Date"+i).value =  util.printd("mm/dd/yyyy",dtWkDay.setDate(dtWkDay.getDate()+1));

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