Copy link to clipboard
Copied
In my Adobe Acrobat Pro DC.
I don't have the date and image icons, but with a script i was able to make date work in a couple of my forms but, when i tried to do the same in another form it would not work. I went back one of the other forms that was working, and they are not working any more.
Copy link to clipboard
Copied
Thank you, its working now.
Copy link to clipboard
Copied
Since a special custom script needs to be added to the form and that script requires some additional form fields and code to work, it is pretty hard to find an error without seeing all the code and a sample of the form.
Copy link to clipboard
Copied
Please explain more, What do you mean by make date work? and what do icons have to do with this?
Copy link to clipboard
Copied
Hello Thom,
I am creating a form that each day I open it, “today’s date” will appear; then I would like it to post a date 45 days later such as “Expiration Date”
Copy link to clipboard
Copied
And you have scripts for this? and they worked at one time?
Please post the scripts and indicate the location of each script within the PDF.
Copy link to clipboard
Copied
Today’s date:
(function () {
var sDate = getField("OriginalDate").valueAsString;
var d = util.scand("mm/dd/yyyy", sDate);
var days = getField("DaysAdded").value;
d.setDate(d.getDate() + days);
if (sDate) {
event.value = util.printd("mm/dd/yyyy", d);
} else {
event.value = "";
}
})();
Today’s date plus 45:
(function () {
var sDate = getField("OriginalDate").valueAsString;
var d = util.scand("mm/dd/yyyy", sDate);
var days = getField("DaysAdded").value;
d.setDate(d.getDate() + 45);
if (sDate) {
event.value = util.printd("mm/dd/yyyy", d);
} else {
event.value = "";
}
})();
Copy link to clipboard
Copied
We also need to know the action where you placed the code. It looks like it would be the field calculation actionl. You need to enter a valid date string into the field "Original Date" for the calculations to be performed.
If you want the current date to appear in the "Original Date" field automatically, then you need to add a document level script like:
this.getField("OriginalDate").value = util.printd("mm/dd/yyyy", new Date());
It looks like you just cut and pasted someone else's code with any thought.
Copy link to clipboard
Copied
I am new and don’t know how to do the codes, I have copied them from the forum. Here is the part of the form where I need the dates.
Copy link to clipboard
Copied
Both scripts you posted are nearly identical. Neither one gets today's date.
What they do is get a date string from a field named "OriginalDate" and add days to it from another field named "DaysAdded".
if either of these fields was missing from the form, then the scripts would fail. This seems like the most likely reason the script stopped working.
Copy link to clipboard
Copied
What scripts would I use?
Regards,
Jim Vogel
Office: +1 (317) 770-6315
INDEX Corporation
Copy link to clipboard
Copied
GKaiseril already gave you the script for getting the current date when the document is opened.
Add this code to the same script, it adds 45 days to the current date. Change "Expiration Date" to the name of your field that is suppose to contain today's date + 45 days.
var d = new Date;
d.setDate(d.getDate() + 45);
this.getField("Expiration Date").value = util.printd("mm/dd/yyyy", d);
Copy link to clipboard
Copied
Thank you, its working now.
Copy link to clipboard
Copied
I would start with just getting today's date to populate a field upon opening the PDF. Then work on adding 15 days to the date.
This is a public and very open forum, you should not be publishing personal information in your posts.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more