Copy link to clipboard
Copied
Hello, I'm having trouble with a PDF document script to reset fields when the document is opened on a different date than the date of the last edit. I've tried the code below, but it didn't work for me. Can someone here assist me with this? Thanks
function clearFormOnNewDate() {
var today = new Date();
var lastFilledDate = this.getField("date").value; // Replace "date" with the actual field name in your PDF
if (lastFilledDate != today.toLocaleDateString()) {
this.getField("date").value = "";
this.getField("off").value = "Select Off";
this.getField("untitled9").value = "";
// Clears fields
}
}
Copy link to clipboard
Copied
It's using a field value. You can use the date last saved. It's called the modified date. You can obtain it in a script like this: info.modDate;
You will have to convert both date objects to an identical string format to make the correct comparison. Enter the following as a document level script:
if(util.printd("mm/dd/yyyy",info.modDate)!=util.printd("mm/dd/yyyy",new Date()))
{
this.getField("date").value = "";
this.getField("off").value = "Select Off";
this.getField("untitled9").value = "";
}
Copy link to clipboard
Copied
Is that a document level script? If so, you either need to add the function call below it:
clearFormOnNewDate();
or remove the script from the function:
var today = new Date();
var lastFilledDate = this.getField("date").value; // Replace "date" with the actual field name in your PDF
if (lastFilledDate != today.toLocaleDateString()) {
this.getField("date").value = "";
this.getField("off").value = "Select Off";
this.getField("untitled9").value = "";
// Clears fields
}
Also, is the date field formatted exactly the same as toLocaleDateString()? You might be better off convering the date field string to a date object then converting that object and today's date object to the same string format to compare.
Copy link to clipboard
Copied
Thanks for your response. I didn't include clearFormOnNewDate(); here by mistake, but I did have it in the PDF. I think I was confused by how this code was working. I thought it was using the date "date" was last edited vs the date actually typed in "date". Now, I understand how it could be causing an issue. I will try your suggestion.
Copy link to clipboard
Copied
It's using a field value. You can use the date last saved. It's called the modified date. You can obtain it in a script like this: info.modDate;
You will have to convert both date objects to an identical string format to make the correct comparison. Enter the following as a document level script:
if(util.printd("mm/dd/yyyy",info.modDate)!=util.printd("mm/dd/yyyy",new Date()))
{
this.getField("date").value = "";
this.getField("off").value = "Select Off";
this.getField("untitled9").value = "";
}
Copy link to clipboard
Copied
It works. Thanks!