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

Javascript - Date Auto-Population Help

Community Beginner ,
Jan 31, 2019 Jan 31, 2019

Copy link to clipboard

Copied

A form that was previously working perfectly now seems to be giving me some grief with the New Year having come upon us. This form is set to start at the current month and go back one month concurrently as below:

1/2019   12/2018  11/2018  10/2018  9/2018

It was doing this until the new year of 2019 came up and now it's duplicating some dates and looks like..

1/2019  12/2018  12/2018  10/2018  10/2018

I'm looking for some help to fix this issue and get it back to the way it is meant to be updating.

Document level Javascripts are:

To get first field:

this.getField("Today").value = util.printd("mm/yyyy", new Date());   

To get other fields:

function getPastDate(Today, months){

    var v = this.getField(Today).valueAsString

    if (v=="") return "";

    var cDate = util.scand("dd/mm/yyyy",new Date("01/"+v));

    if (cDate== null){

        app.alert("Please enter a valid date of the form \"mm/yyyy\".")

        return "";

    } else {

        cDate.setMonth(cDate.getMonth() + months);

        return util.printd("mm/yyyy",cDate);

    }

}

Field level Javascript:

event.value = getPastDate("Today",-1);               results in 12/2018

event.value = getPastDate("Today",-2);               results in 12/2018

Please help!

Thank you!

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

correct answers 1 Correct answer

Community Expert , Jan 31, 2019 Jan 31, 2019

I think the issue is with this part of the code:

new Date("01/"+v)

That is not how you instantiate a Date object. Run this code from the console and see what the output is:

new Date("01/02/2019")

You don't need to create a date object there at all... Just do it directly, like this:

var cDate = util.scand("dd/mm/yyyy","01/"+v);

Votes

Translate

Translate
Community Expert ,
Jan 31, 2019 Jan 31, 2019

Copy link to clipboard

Copied

I think the issue is with this part of the code:

new Date("01/"+v)

That is not how you instantiate a Date object. Run this code from the console and see what the output is:

new Date("01/02/2019")

You don't need to create a date object there at all... Just do it directly, like this:

var cDate = util.scand("dd/mm/yyyy","01/"+v);

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 ,
Feb 01, 2019 Feb 01, 2019

Copy link to clipboard

Copied

When the date changed to 2/1/2019 in the first field today, all the fields populated today. Will this coding fix this issue?

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 01, 2019 Feb 01, 2019

Copy link to clipboard

Copied

It should do, yes.

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 ,
Feb 01, 2019 Feb 01, 2019

Copy link to clipboard

Copied

LATEST

I had my IT department revert my computer date to yesterday to work and it worked perfectly. Thank you!

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