Copy link to clipboard
Copied
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.
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 = "";
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
No, if you placed the code where I suggested then it should happen automatically.
Copy link to clipboard
Copied
I placed the code in the Custom calculation script in the text field properties. When the date is changed up top the months do not change. It does populate correctly the first time but if I change the month it stays exactly the same.
Copy link to clipboard
Copied
Check the JS Console for error messages.
Copy link to clipboard
Copied
There are no errors showing up.
Copy link to clipboard
Copied
Can you share the actual file with us?
You can attach it to the original message using the tiny paperclip icon at the bottom when you edit it, or upload it to a file-sharing website (like Dropbox, Google Drive, Adobe Cloud, etc.), generate a share link and then post it here.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 = "";
Copy link to clipboard
Copied
That worked thank you so much!!