Custom Calculation to set date based on another date field

New Here ,
Nov 07, 2018

Copy link to clipboard

Copied

I'm working with two date fields.  When a date is entered into the first field(LeaseStart_af_date), I need the second field(BillStart_af_date) to display the 1st day of the month following.

So, if Lease Start date is 11/07/2018

Bill Start should be 12/01/2018

I'm using a custom calculation script for BillStart_af_date but it is not calculating.  The field 'LeaseStart_af_date' does not use any calculation.  Neither field is validated.  Both fields have format set to 'Date mm/dd/yyyy'.  I'm sure its an error with my script.  Any help would be appreciated.

var d = util.scand("mm/dd/yyyy",this.getField("LeaseStart_af_date").valueAsString);

if (d.getMonth() == 11) {

    d.setMonth(0);

    d.setFullYear(d.getFullYear() + 1);

}

else {

    d.setMonth(d.getMonth() + 1);

    d.setDate(1);

}

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You're not applying the value to the field... Add this line at the end of your code:

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

TOPICS
Acrobat SDK and JavaScript, Windows

Views

472

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

Custom Calculation to set date based on another date field

New Here ,
Nov 07, 2018

Copy link to clipboard

Copied

I'm working with two date fields.  When a date is entered into the first field(LeaseStart_af_date), I need the second field(BillStart_af_date) to display the 1st day of the month following.

So, if Lease Start date is 11/07/2018

Bill Start should be 12/01/2018

I'm using a custom calculation script for BillStart_af_date but it is not calculating.  The field 'LeaseStart_af_date' does not use any calculation.  Neither field is validated.  Both fields have format set to 'Date mm/dd/yyyy'.  I'm sure its an error with my script.  Any help would be appreciated.

var d = util.scand("mm/dd/yyyy",this.getField("LeaseStart_af_date").valueAsString);

if (d.getMonth() == 11) {

    d.setMonth(0);

    d.setFullYear(d.getFullYear() + 1);

}

else {

    d.setMonth(d.getMonth() + 1);

    d.setDate(1);

}

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You're not applying the value to the field... Add this line at the end of your code:

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

TOPICS
Acrobat SDK and JavaScript, Windows

Views

473

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
Nov 07, 2018 0
Most Valuable Participant ,
Nov 07, 2018

Copy link to clipboard

Copied

You're not applying the value to the field... Add this line at the end of your code:

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...
Nov 07, 2018 1
New Here ,
Nov 08, 2018

Copy link to clipboard

Copied

Thank you so much.  Gosh - I can't believe I missed that.  Works perfectly.

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...
Nov 08, 2018 0