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

Custom Dynamic Date Stamp Dialogue Box Results not Displaying

Community Beginner ,
May 28, 2020 May 28, 2020

Copy link to clipboard

Copied

Hello,

 

I am completely a novice at this, and borrowed part of a script from a sample online.

 

I am working a stamp with a dialogue box prompting for the date, and defaulting to the current date if no response. I have gotten it to display the dialogue box and the default date. But, the results don't end up on the stamp. Could someone please assist on resooving the issues?

 

if(event.source.forReal && (event.source.stampName == "#2Nw2jMn7S5l9QIPW-WGOHB"))

{

   var rgEmpty = /^\s*$/;

   var cDate = null;

   var cDfltDate = null;

   if((event.value != null)  && !rgEmpty.test(event.value) && util.scand("mmm dd yyyy",event.value))

      cDfltDate = event.value;

   else

      cDfltDate = util.printd("mmm dd yyyy",new Date());

   while((cDate==null) || rgEmpty.test(cDate) || (null == util.scand("mmm dd yyyy",cDate)))

   {

       cDate = app.response({cQuestion:"Please Enter the Date",

                             cTitle:"Stamp Date Entry",

                             cDefault:cDfltDate ,

                             cLabel:"Date:"

                           });

       if((cDate==null) || rgEmpty.test(cDate) || (null == util.scand("mmm dd yyyy",cDate)))

       {

          app.alert("Please enter date as \"mmm dd yyyy\"\n\nEx: Apr 15 2020",1);

          if(cDate != null)

            cDfltDate = cDate;

       }

   }

}

 

Also, I would like to distribute the final stamp to my coworkers as a template rather than them creating the script. Can I share the stamp pdf, and have them create one off my template without them having to modify the script?

 

Thank you!

TOPICS
Acrobat SDK and JavaScript

Views

1.5K

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 Beginner , May 29, 2020 May 29, 2020

IT WORKS!!!

 

The date is required in oder to be official, and this specific format is also required. So, I think the exit of simply clicking OK is good enough because it gives a default date automatically.

 

Last thing to test is that an end user can just copy it directly into the stamps folder and start using it. I will test that out this morning when someone is available and follow up.

 

Thank you for your help!

 

Here is the code that worked:

 

console.println("Stamping:" + event.source.StampName);

 

if

...

Votes

Translate

Translate
Community Expert ,
May 28, 2020 May 28, 2020

Copy link to clipboard

Copied

You does not set the value of the field.

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 Beginner ,
May 28, 2020 May 28, 2020

Copy link to clipboard

Copied

Could you elaborate please? How do I set the 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
Community Expert ,
May 28, 2020 May 28, 2020

Copy link to clipboard

Copied

You set the value of a field like this (in its calculation script):

event.value = (some value);

In your case it should probably be:

event.value = cDate;

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 ,
May 28, 2020 May 28, 2020

Copy link to clipboard

Copied

So the script you posted is a calculation script in a field on the stamp? 

I would imagine that this field is the field you want the date to be displayed in?

If this is the case, then make this the last bit of code (inside the while).

 

       if((cDate==null) || rgEmpty.test(cDate) || (null == util.scand("mmm dd yyyy",cDate)))

       {

          app.alert("Please enter date as \"mmm dd yyyy\"\n\nEx: Apr 15 2020",1);

       }

       else

            event.value = cDate;

 

BTW, you should have an escape to allow the user out of the loop if they just can't enter a valid date.

 

Also, dynamic stamps have to be installed by copying the stamp file into one of the two Acrobat stamp folders. 

Read about it here:

https://www.pdfscripting.com/public/Installing-a-PDF-Stamp-into-Acrobat-Macintosh-and-Windows.cfm

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 Beginner ,
May 28, 2020 May 28, 2020

Copy link to clipboard

Copied

Thank you both!

I will give those suggestions a try tomorrow when I'm back on the work computer. 

Yes, this script runs on a date field in a date stamp for received documents. Typically the current date is used. The intent is to default the current date. But, to give the option to backdate if needed.

Yes, I'm familiar with the user stamps folder location. The app stamps location is restricted on our access.

I'm hoping I will ultimately be able to share the finalized stamp template with coworkers to simply copy onto the stamps folder and begin using it without further setup or configuration needed. 

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 Beginner ,
May 29, 2020 May 29, 2020

Copy link to clipboard

Copied

IT WORKS!!!

 

The date is required in oder to be official, and this specific format is also required. So, I think the exit of simply clicking OK is good enough because it gives a default date automatically.

 

Last thing to test is that an end user can just copy it directly into the stamps folder and start using it. I will test that out this morning when someone is available and follow up.

 

Thank you for your help!

 

Here is the code that worked:

 

console.println("Stamping:" + event.source.StampName);

 

if(event.source.forReal && (event.source.stampName == "#StampTemplate"))

{

   var rgEmpty = /^\s*$/;

   var cDate = null;

   var cDfltDate = null;

   if((event.value != null)  && !rgEmpty.test(event.value) && util.scand("mmm dd yyyy",event.value))

      cDfltDate = event.value;

   else

      cDfltDate = util.printd("mmm dd yyyy",new Date());

   while((cDate==null) || rgEmpty.test(cDate) || (null == util.scand("mmm dd yyyy",cDate)))

   {

       cDate = app.response({cQuestion:"Please enter date as \"mmm dd yyyy\"\n\nFor Example: Apr 15 2020",

                             cTitle:"Stamp Date Entry",

                             cDefault:cDfltDate ,

                             cLabel:"Date:"

                           });

       if((cDate==null) || rgEmpty.test(cDate) || (null == util.scand("mmm dd yyyy",cDate)))

       {

          app.alert("Please enter date as \"mmm dd yyyy\"\n\nFor Example: Apr 15 2020",1)

       }

       else

          event.value = cDate;

       }

}

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 ,
May 29, 2020 May 29, 2020

Copy link to clipboard

Copied

Yes, that should be possible. Just make sure they don't try to use the file you send them to create a new Stamp from within Acrobat. They have to copy it as-is into the Stamps folder.

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 Beginner ,
May 29, 2020 May 29, 2020

Copy link to clipboard

Copied

Thank you, yes that's the plan. I will recreate the job aid and screenshots once I confirm it works.

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 Beginner ,
May 29, 2020 May 29, 2020

Copy link to clipboard

Copied

LATEST

Everything went to plan, thanks again everyone!

 

Hope this is useful for anyone looking to achieve a similar result.

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