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

I have a random quote number set up to generate each time my PDF form opens. How can I get this number to save in order to keep a copy of the form?

New Here ,
Jan 30, 2019 Jan 30, 2019

Copy link to clipboard

Copied

My quote generator code is currently set at document level (see below);

this.getField("quote_number").value = util.printf("%06d", Math.floor((Math.random() * 1000000) + 1));

I would like to be able to save a copy of the form after it is filled out, but when I save the form now and reopen it, it generates a new quote number.

I believe this can be done using a global object, but I am not sure how to set that up.

Any advice is greatly appreciated!

Thank you in advance! 🙂

TOPICS
Acrobat SDK and JavaScript

Views

416

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 ,
Jan 30, 2019 Jan 30, 2019

Copy link to clipboard

Copied

You need to clearly define when the number should change, and when it shouldn't.

For example, you can set it up so that it will only change if the field is empty.

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
New Here ,
Jan 31, 2019 Jan 31, 2019

Copy link to clipboard

Copied

Thank you, but I'm not sure I understand?

The field automatically generates a number, meaning it is never empty.

I would like the number to "stick" on save, so that a copy of the form can be saved.

Not sure how to write this, or where to put it in the PDF document.

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 ,
Jan 31, 2019 Jan 31, 2019

Copy link to clipboard

Copied

So after the file is saved the field should never update again? In that case, you might as well set it to only populate when the field is empty, and then clear it (with JavaScript disabled), to achieve it.

To do that change your code to:

if (this.getField("quote_number").valueAsString=="")

     this.getField("quote_number").value = util.printf("%06d", Math.floor((Math.random() * 1000000) + 1));

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
New Here ,
Jan 31, 2019 Jan 31, 2019

Copy link to clipboard

Copied

LATEST

Thank you so much for your help! That works 🙂

Is there any way to have the template continue to generate a random number, then execute that script once the form has been filled out and saved?

Not sure if that makes sense...My client will be reusing the form, so they will need to generate a new quote number once the template is opened, then once they have filled it out for a customer, I would like them to be able to save that copy with the same quote number so they can refer back to it.

Is that possible?

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