Highlighted

Auto Fill a Month and year

New Here ,
Oct 30, 2020

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. 

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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 = "";

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

70

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 Fill a Month and year

New Here ,
Oct 30, 2020

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. 

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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 = "";

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

71

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
Oct 30, 2020 0
Most Valuable Participant ,
Oct 30, 2020

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

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...
Oct 30, 2020 0
New Here ,
Nov 02, 2020

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?

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 02, 2020 0
Most Valuable Participant ,
Nov 02, 2020

Copy link to clipboard

Copied

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

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 02, 2020 0
New Here ,
Nov 02, 2020

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. 

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 02, 2020 0
Most Valuable Participant ,
Nov 02, 2020

Copy link to clipboard

Copied

Check the JS Console for error messages.

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 02, 2020 0
New Here ,
Nov 02, 2020

Copy link to clipboard

Copied

There are no errors showing up. 

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 02, 2020 0
Most Valuable Participant ,
Nov 02, 2020

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.

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 02, 2020 0
New Here ,
Nov 03, 2020

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. 

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 03, 2020 0
Most Valuable Participant ,
Nov 03, 2020

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 = "";

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 03, 2020 0
New Here ,
Nov 03, 2020

Copy link to clipboard

Copied

That worked thank you so much!!

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 03, 2020 0