Skip to main content
Known Participant
October 30, 2020
Answered

Auto Fill a Month and year

  • October 30, 2020
  • 1 reply
  • 972 views

I want to take the requested date of a form and auto fill boxes 6, 5, 4, 3, 2, 1 month prior to that date. Is this possible? I have tried a few other date formula's and they are not working. I want the requested date to be mm/dd/yy format and the boxes to fill in a mmm-yy format. 

This topic has been closed for replies.
Correct answer try67

Here is the custom calculation script I am using: 

var requestDateString = this.getField("RequestDate").valueAsString;

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

else {

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

d.setMonth(d.getMonth()-6);

event.value = util.printd("mmm-yy", d);

}

I am unable to attach the document because I am on a federal laptop with so many restrictions. When I initially choose the request date the mmm-yy fills automatically as needed but when I change the request date the original mmm-yy box stays the same and does not update with the date change. 


Sorry, my bad. There's a small error in the code I posted before.

Change this line:

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

To:

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

1 reply

try67
Community Expert
Community Expert
October 30, 2020

Yes, it's possible. Here's how to do it for the one 6 months prior. You can use that code for the other boxes, with minor adjustments, as their custom calculation script:

 

var requestDateString = this.getField("RequestDate").valueAsString;

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

else {

var d = util.scand("mm/dd/yy", requestDateString );

d.setMonth(d.getMonth()-6);

event.value = util.printd("mmm-yy", d);

}

 

Edit: Small mistake in the code fixed

Known Participant
November 2, 2020

Thank you this did exactly what I wanted it to do but when I change the date in the form they months in the other boxes do not change. Would this be an added string?

try67
Community Expert
Community Expert
November 2, 2020

No, if you placed the code where I suggested then it should happen automatically.