Skip to main content
Participant
November 7, 2018
Answered

Custom Calculation to set date based on another date field

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);

}

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
November 7, 2018

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);

2 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
November 7, 2018

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);

Translate
Participant
November 8, 2018

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

Translate