Auto populate dates of week

New Here ,
Apr 02, 2018

Copy link to clipboard

Copied

I'm building a form which populates the date fields for Monday through Saturday from the Sunday field "WENDING". The following custom calculation script is for the Saturday date field, but shows a "SyntaxError: missing ) after argument list".

var dayMs = 86400000;

event.value = util.printd("mm/dd/yyyy", util.scand("mm/dd/yyyy, this.getField("WENDING").valueAsString).getTime() - dayMs);

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Adding milliseconds is tricky because of things like the change to/from daylight savings time, which mess it up.

A better approach is to do it like this:

var sundayString = this.getField("WENDING").valueAsString;

if (sundayString=="") event.value = "";

else {

    var d = util.scand("mm/dd/yyyy", sundayString);

    d.setDate(d.getDate()+1);

    event.value = util.printd("mm/dd/yyyy", d);  

}

TOPICS
Acrobat SDK and JavaScript

Views

121

Likes

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

Auto populate dates of week

New Here ,
Apr 02, 2018

Copy link to clipboard

Copied

I'm building a form which populates the date fields for Monday through Saturday from the Sunday field "WENDING". The following custom calculation script is for the Saturday date field, but shows a "SyntaxError: missing ) after argument list".

var dayMs = 86400000;

event.value = util.printd("mm/dd/yyyy", util.scand("mm/dd/yyyy, this.getField("WENDING").valueAsString).getTime() - dayMs);

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Adding milliseconds is tricky because of things like the change to/from daylight savings time, which mess it up.

A better approach is to do it like this:

var sundayString = this.getField("WENDING").valueAsString;

if (sundayString=="") event.value = "";

else {

    var d = util.scand("mm/dd/yyyy", sundayString);

    d.setDate(d.getDate()+1);

    event.value = util.printd("mm/dd/yyyy", d);  

}

TOPICS
Acrobat SDK and JavaScript

Views

122

Likes

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
Apr 02, 2018 0
New Here ,
Apr 02, 2018

Copy link to clipboard

Copied

I'm a beginner, so I'm not sure I'm using these methods correctly either

Likes

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
Reply
Loading...
Apr 02, 2018 0
Most Valuable Participant ,
Apr 02, 2018

Copy link to clipboard

Copied

Adding milliseconds is tricky because of things like the change to/from daylight savings time, which mess it up.

A better approach is to do it like this:

var sundayString = this.getField("WENDING").valueAsString;

if (sundayString=="") event.value = "";

else {

    var d = util.scand("mm/dd/yyyy", sundayString);

    d.setDate(d.getDate()+1);

    event.value = util.printd("mm/dd/yyyy", d);  

}

Likes

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
Reply
Loading...
Apr 02, 2018 1
New Here ,
Apr 02, 2018

Copy link to clipboard

Copied

Works like a charm, thanks!

Likes

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
Reply
Loading...
Apr 02, 2018 0