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

PDF script to clear fields

Participant ,
Feb 01, 2025 Feb 01, 2025

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

        }

    }
TOPICS
Edit and convert PDFs , How to , JavaScript , PDF , PDF forms

Views

80

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 ACCEPTED SOLUTION
Community Expert ,
Feb 01, 2025 Feb 01, 2025

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

 

View solution in original post

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 ,
Feb 01, 2025 Feb 01, 2025

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.

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
Participant ,
Feb 01, 2025 Feb 01, 2025

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.  

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 ,
Feb 01, 2025 Feb 01, 2025

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

 

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
Participant ,
Feb 02, 2025 Feb 02, 2025

Copy link to clipboard

Copied

LATEST

It works. Thanks!

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