Make JavaScript Stop Performing Once Saved

Community Beginner ,
Jan 10, 2020 Jan 10, 2020

Copy link to clipboard

Copied

I have a document javascript that autoincreases a quote number on a form each time the document is opened.  The user opens the form, fills it out and completes the form (with a button that makes all form fields read-only) and then saves the form as a new document name to their desktop.  The problem is if they then re-open the completed form the quote number still changes.  When the quote is sent to a customer and they open it, the quote number changes and then we aren't able to track the quote because the customer may refer to one quote number that they get when they open a form but that's not the quote number that was originally on the form and saved in the system.  I need a way to make this javascript stop running when the document is saved or something so the quote number stays the same each time its opened AFTER its been completed and saved.  Any ideas?  Here is the javascript i'm using to auto-generate a quote number each time the form is opened.

 

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

 

Thanks!

TOPICS
General troubleshooting , How to , PDF forms

Views

243

Likes

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

Adobe Community Professional , Jan 11, 2020 Jan 11, 2020

Use this:

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

Likes

Translate

Translate
Adobe Community Professional ,
Jan 10, 2020 Jan 10, 2020

Copy link to clipboard

Copied

Set the value of the field when the field is empty.

Likes

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
Adobe Community Professional ,
Jan 11, 2020 Jan 11, 2020

Copy link to clipboard

Copied

Since your button locks all fields it can also remove the script.

JavaScript don't allow to remove a document script, but you can use the "addScript" method to overwrite the existing one and replace it by a double-slash or by nothing at all.

See: https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/Acro12_MasterBook/JS_API_AcroJS/Do...

Likes

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
Adobe Community Professional ,
Jan 11, 2020 Jan 11, 2020

Copy link to clipboard

Copied

That won't work in Reader, though.

Likes

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 ,
Jan 11, 2020 Jan 11, 2020

Copy link to clipboard

Copied

Ok any ideas on what i could do then?  Because the users that will be using the form will be using reader.

Likes

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
Adobe Community Professional ,
Jan 11, 2020 Jan 11, 2020

Copy link to clipboard

Copied

Use this:

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

Likes

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 ,
Jul 12, 2022 Jul 12, 2022

Copy link to clipboard

Copied

LATEST

Hi,

Can you tell me how to use this script, but change it to produce a sequential number please.

Ms. V

Likes

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
Adobe Community Professional ,
Jan 11, 2020 Jan 11, 2020

Copy link to clipboard

Copied

That won't work in Reader

Yes. I forgot this "small detail" 😉

Likes

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 ,
Jan 11, 2020 Jan 11, 2020

Copy link to clipboard

Copied

I tried that and it works when you complete the form but it doesn't autog-generate a new quote number when the form is first opened before it's completed.  Is that because the field isn't empty?

Likes

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 ,
Jan 11, 2020 Jan 11, 2020

Copy link to clipboard

Copied

Sorry i forgot to say @Bernd with my comment above.

Likes

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
Adobe Community Professional ,
Jan 11, 2020 Jan 11, 2020

Copy link to clipboard

Copied

Clear the field before you save the form.

Likes

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 ,
Jan 11, 2020 Jan 11, 2020

Copy link to clipboard

Copied

THANK YOU!! THAT WORKED! 

Likes

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