• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Auto Fill a Month and year

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

TOPICS
Acrobat SDK and JavaScript

Views

454

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
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 03, 2020 Nov 03, 2020

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

Votes

Translate

Translate
Community Expert ,
Oct 30, 2020 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

Votes

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
community guidelines
New Here ,
Nov 02, 2020 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?

Votes

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
community guidelines
Community Expert ,
Nov 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

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

Votes

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
community guidelines
New Here ,
Nov 02, 2020 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. 

Votes

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
community guidelines
Community Expert ,
Nov 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

Check the JS Console for error messages.

Votes

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

Copy link to clipboard

Copied

There are no errors showing up. 

Votes

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
community guidelines
Community Expert ,
Nov 02, 2020 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.

Votes

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
community guidelines
New Here ,
Nov 03, 2020 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. 

Votes

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
community guidelines
Community Expert ,
Nov 03, 2020 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 = "";

Votes

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

Copy link to clipboard

Copied

LATEST

That worked thank you so much!!

Votes

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
community guidelines