Skip to main content
Inspiring
December 2, 2016
Answered

Auto generate a number and prevent it from updating when the form is opened

  • December 2, 2016
  • 2 replies
  • 977 views

Hello

I've created a form which will be uploaded to our intranet, the form has a field which automatically generates a random number when the form is opened, that works well but, the number changes when the file is saved or opened.

Initially the code was in the document processing so ran when the form was opened, I've now deleted that and added the code to the field itself but it's still changing if the user goes into the field.

This is the code I've used 

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

It's set on a mouse up action and the locked option is also selected.

I want the number to generate when the form is opened and then lock so it doesn't change when opened again, can this be done?

I'm used Adobe Acrobat Pro 9.

Any help would be appreciated.

This topic has been closed for replies.
Correct answer try67

Move it back to where it was. Just add this line before it:

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

2 replies

JR Boulay
Community Expert
Community Expert
December 2, 2016

Hi.

You should be aware that all PDFs embed an unique "Permanent identification number" that you can use instead of creating anoter one:

http://abracadabrapdf.net/utilities-in-english/abracadabra-doc-id_en/

Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
December 2, 2016

Move it back to where it was. Just add this line before it:

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

EllenBCCAuthor
Inspiring
December 2, 2016

Thank you so much,that was a super fast response and works perfectly.  You are a star