Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Inserting an auto-populate date that is a year from another auto-populated date

New Here ,
Jun 23, 2021 Jun 23, 2021

Copy link to clipboard

Copied

I inserted a field that has today's date auto-populate. I want to create another field that will auto-populate a date that is the same month and day but the year will be the NEXT year.

 

Using today as an example:

Here is the auto-populated field for today's date

CourtGinger_0-1624485623543.png

And this is what it's called: 

CourtGinger_1-1624485665027.png

I need a field that will populate the date to Jun 23, 2022 automatically (based off the other date).

Hope that made sense.

 

Is this possible? 

TOPICS
Comment review and collaborate PDF, Edit and convert PDFs, General troubleshooting, JavaScript, PDF forms

Views

1.2K

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

correct answers 1 Correct answer

Adobe Community Professional , Jun 24, 2021 Jun 24, 2021
A better solution is to use the built-in methods of the Date object to do it, which will take care of the Feb 29th issue without having to hard-code each leap year into it: var sDate = this.getField("Cur_Date").valueAsString; if (sDate) { var cDate = util.scand("mmm dd, yyyy", sDate); cDate.setFullYear(cDate.getFullYear()+1); event.value = util.printd("mmm dd, yyyy", cDate); } else event.value = "";

Likes

Translate

Translate
Adobe Employee ,
Jun 23, 2021 Jun 23, 2021

Copy link to clipboard

Copied

Hi there

 

Hope you are doing well and sorry for the trouble. As described you want to populate the date field that has the same month and day but the year will be the NEXT year.

 

The workflow that you are trying to achieve is possible using the JavaScript. For more information please check the help page https://acrobatusers.com/tutorials/javascript_console/ and see if that works for you.

 

Regards

Amal

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
community guidelines
Engaged ,
Jun 23, 2021 Jun 23, 2021

Copy link to clipboard

Copied

@Court & Ginger  use the following script with necessary changes to get a required year :

It is not the best of the answers but it will do for your requirement.

 

//Script:

cDate = util.scand("mmm dd, yyyy", this.getField("Cur_Date").value); //change "Curr_Date" to your date field name
cDay = util.printd("dd",cDate);
cMonth = util.printd("mmm",cDate);
cYear = Number(util.printd("yyyy",cDate)) + 1;   

event.value = cMonth + " " + cDay + ", " + cYear;

 

 

 

 

Hope it helps

 

 

 

 

 

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
community guidelines
Adobe Community Professional ,
Jun 23, 2021 Jun 23, 2021

Copy link to clipboard

Copied

What is with Feb 29, 2024?

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
community guidelines
Engaged ,
Jun 23, 2021 Jun 23, 2021

Copy link to clipboard

Copied

@Bernd Alheit  Sir,   i know previous script was not the best of the answer

Plz check this one:


cDate = util.scand("mm/dd/yy", this.getField("Cur_Date").value);;
cDay = util.printd("dd",cDate);
cMonth = Number(util.printd("mm",cDate));
cYear = Number(util.printd("yyyy",cDate));

 

if(cYear%4 == "0" && cMonth == "2" && cDay == "29"){
event.value = (cMonth+1)+ "/" + "1" + "/" + (cYear+1);}


else if(cYear%4 !== "0" && cMonth !== "2" && cDay !== "29") {

event.value = cMonth + "/" + cDay + "/" + (cYear+1)};

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
community guidelines
Adobe Community Professional ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

Why not Feb 28?

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
community guidelines
Engaged ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

I reckon in this particular case since the date is autopopulated with current date so for next 50 years   cYear%4=="0" will hold good.

 

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
community guidelines
Engaged ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

it depends on the user requirement if  he wants 28 then it can be changed .

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
community guidelines
Enthusiast ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

What would be correct solution in this case, to show march 1st?

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
community guidelines
Engaged ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

@Asim123 I have updated the Script plz check updated Script to take care of Feb 29 situation.

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
community guidelines
Adobe Community Professional ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

A better solution is to use the built-in methods of the Date object to do it, which will take care of the Feb 29th issue without having to hard-code each leap year into it:

 

var sDate = this.getField("Cur_Date").valueAsString;
if (sDate) {
	var cDate = util.scand("mmm dd, yyyy", sDate);
	cDate.setFullYear(cDate.getFullYear()+1);
	event.value = util.printd("mmm dd, yyyy", cDate);
} else 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
community guidelines
New Here ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

I am trying to respond and it won't post

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
community guidelines
New Here ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

Thank you everyone for taking the time to figure this out.

 

I forgot to mention that I know nothing about Javascript coding so I need a step by step version lol.

 

I'm assuming that I will need to copy and paste the script below somewhere but that's all I know:

CourtGinger_0-1624546391753.png

Plus I don't know how this will work with other other script that I have for auto-populating today's date:

CourtGinger_0-1624546158348.png

 

Thank you for your patience!

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
community guidelines
Adobe Community Professional ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

You need to use this code as the custom calculation script of the second field, and you must adjust the name of the field in the first line of the code to match the actual field name in your file where the current date will appear.

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
community guidelines
New Here ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

Ok this is what I tried:.

 

I created a new field and named it this:

CourtGinger_1-1624555036843.png

 

Then I clicked on Javascript editor, clicked on document JavaScripts, and created a new script:

CourtGinger_2-1624555109534.png

 

In Microsoft Word, I typed in the script that you gave me (as best I can), and then copied and pasted it into

the Java sript editor (this is my text from word):

 

CourtGinger_6-1624555504358.png

 

 

Clicked OK, and then it said I had a syntax error: 

CourtGinger_5-1624555370996.png

(The part circled in red above is what was highlighted after I hit "Ok" but when I took a screen shot of it, it highlighted the whole script for some reason)

 

Do you know where my error is?

 

 

 

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
community guidelines
Adobe Community Professional ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

The field name has to be in quotes. Also, do not use Word as a code editor! Use a plain-text editor, like Notepad. Or if you want a more professional tool, I highly recommend Notepad++.

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
community guidelines
New Here ,
Jun 28, 2021 Jun 28, 2021

Copy link to clipboard

Copied

Ok thank you. I typed up the code in Notepad instead.

 

It didn't show it had an error this time but it's not working:

 

CourtGinger_2-1624901417188.png

CourtGinger_0-1624901639822.png

 

CourtGinger_3-1624901460988.png

The second date should be June 28, 2022

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
community guidelines
Adobe Community Professional ,
Jun 28, 2021 Jun 28, 2021

Copy link to clipboard

Copied

You need to place that code under the custom calculation event of the second field, not as a doc-level script, or alternatively adjust it so that it refers to the field, not to event.value, which won't work in this context.

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
community guidelines
New Here ,
Jun 29, 2021 Jun 29, 2021

Copy link to clipboard

Copied

Oh ok. I have no idea how to do that lol.

 

Would you mind taking me through each step?

 

It sounds like adjusting it "so that it refers to the field, not to event.value" might be the easier option for me since I have an idea of how to do the doc-level script.

 

Thank you so much for all of the time you are taking to help me!

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
community guidelines
Adobe Community Professional ,
Jun 29, 2021 Jun 29, 2021

Copy link to clipboard

Copied

Change this line:

event.value = util.printd("mmm dd, yyyy", cDate);

To:

this.getField("name of field").value = util.printd("mmm dd, yyyy", cDate);

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
community guidelines
New Here ,
Jun 29, 2021 Jun 29, 2021

Copy link to clipboard

Copied

Ok I tried that and it didn't work (I may have done it wrong) but it seems like I need to do something with the part I put below in red (like remove it or replace it with something else)

 

var sDate = this.getField("Year From Now_es_:signer2:date").valueAsString;
if (sDate) {
var cDate = util.scand("mmm d, yyyy", sDate);
cDate.setFullYear(cDate.getFullYear()+1);
this.getField("Year From Now_es_:signer2:date").value = util.printd("mmm d, yyyy", cDate);
} else 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
community guidelines
Adobe Community Professional ,
Jun 29, 2021 Jun 29, 2021

Copy link to clipboard

Copied

You have to change that too in the same way... However, I don't see when this is going to happen, since the first field will always have a value, no?

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
community guidelines
Adobe Community Professional ,
Jun 29, 2021 Jun 29, 2021

Copy link to clipboard

Copied

You've making it needlessly complicated. This is all the code you need to populate the two fields:

 

var d = new Date();
this.getField("Field1").value = util.printd("mmm dd, yyyy", d);
d.setFullYear(d.getFullYear()+1);
this.getField("Field2").value = util.printd("mmm dd, yyyy", d);

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
community guidelines
New Here ,
Jun 29, 2021 Jun 29, 2021

Copy link to clipboard

Copied

Yay, it worked!

 

Thank you again so much for your patience!

 

Have a great day!

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
community guidelines
New Here ,
Jul 07, 2021 Jul 07, 2021

Copy link to clipboard

Copied

Ok, someting is not working correctly when I send it to be compelted and signed electroincally through Adobe Sign.

 

This is what it looks like before I send it through Adobe sign:

CourtGinger_1-1625686891559.png

 

This is what it looks like after I sent it and the student completed it and signed it through Adobe Sign:

CourtGinger_0-1625686821295.png

 

The second date changes back to 2021 when it should be 2022.

 

Any ideas?

 

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
community guidelines
    • 1
    • 2