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

Creating a unique ID or serial number for a form

Community Beginner ,
Oct 22, 2020 Oct 22, 2020

Copy link to clipboard

Copied

I have a form created, but still a novice. So extended steps may need to be provided(more than likely)- just being honest since I am searching for help.

I have created a form that will be posted in one location and used by multiple people. I need to add a unique id for each as a new document is created. I do have the form set up with a "submit form" to a specific email address as a PDF, for management signature.

 

I do have a read only text field set up named: GL_ID. And I just don't know how to create it to make the magic. This unique identifier can be from 6-8 characters. I would like to attach the magic to the submit button, however it can generate the number upon opening of the document.

 

Please note that any guidance is welcome

jd

TOPICS
Acrobat SDK and JavaScript

Views

7.8K

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 Expert , Oct 23, 2020 Oct 23, 2020

You can use this code as document level script:

this.getField("GL_ID").value = Math.floor(Math.random() * (99999999-999999) +999999);

Every time you open document it will generate random number in GL_ID field.

 

 

Votes

Translate

Translate
Community Expert ,
Oct 23, 2020 Oct 23, 2020

Copy link to clipboard

Copied

You can use this code as document level script:

this.getField("GL_ID").value = Math.floor(Math.random() * (99999999-999999) +999999);

Every time you open document it will generate random number in GL_ID 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 ,
Oct 23, 2020 Oct 23, 2020

Copy link to clipboard

Copied

AWESOME thanks for the response!! now here is the novice part... ummmm where do I place this. sorry and thanks in advance

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 ,
Oct 23, 2020 Oct 23, 2020

Copy link to clipboard

Copied

1.png2.png

You can also open document level script while in prepare form mode by pressing SHIFT+D

 

3.png4.png

After that click "Close" and thats it.

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 ,
Jun 27, 2021 Jun 27, 2021

Copy link to clipboard

Copied

Hi Nesa,

I liked the script, however, my requirement is to generate a serial number for every PDF form. The scenario is to simply open my form, the field named PV# should automatically populate with a unique serial number. So when I open the form for the first time today, the read-only field named PV# should show the number 1, when I open the document next time to generate a new receipt, the field PV# should show the number 2.

 

Can the above be scripted?

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 ,
Jun 27, 2021 Jun 27, 2021

Copy link to clipboard

Copied

Yes, but the number will only be unique if only you open the file. Also, if you save the file (even under a different name), the next time you open it the number will update, which is probably not what you want. You need to define a way of making the number stick, for example by flattening it, or otherwise finalizing it.

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 ,
Jun 27, 2021 Jun 27, 2021

Copy link to clipboard

Copied

I believe this is what I need. Each time I open the same document to generate a receipt, the number will be higher than the previous time.

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 ,
Jun 27, 2021 Jun 27, 2021

Copy link to clipboard

Copied

I don't think it will work like you think it would, but the code to do it is very simple.

Create a (read-only) text field called "Counter" and add the following code under Tools - JavaScript - Document JavaScripts (NOT inside of a function):

 

this.getField("Counter").value = Number(this.getField("Counter").value)+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
Community Expert ,
Jun 27, 2021 Jun 27, 2021

Copy link to clipboard

Copied

Thanks mate, will try it 😊

 

Just tested it, works fantastically. I added a button to reset the form. It resets the number back to 1. I will be careful how to use it… many 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
New Here ,
Jul 16, 2021 Jul 16, 2021

Copy link to clipboard

Copied

Thank you for your grate respond. How can we change the code format?

 

For example;

ABC-Random Number-XYZ

OR

ABC-Random Number

 

Thanks in advance...

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 ,
Jul 16, 2021 Jul 16, 2021

Copy link to clipboard

Copied

LATEST

And one more question, is there possibility to change this number clicking by a created button?

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
LEGEND ,
Oct 23, 2020 Oct 23, 2020

Copy link to clipboard

Copied

By the way, you can make it random, easily enough, but that is not guaranteed unique. If it MUST be unique then you are going to need to store all the numbers you have given out in a central place, making this a much more complex process, needing you to pay for a server to be there 24/7 to keep the info.

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 ,
Oct 23, 2020 Oct 23, 2020

Copy link to clipboard

Copied

the form will be stored on our sharepoint, but i can give up the unique for random. We run a program for free 30 minutes of leave for quality notifications. Unfortunately with telework the employee would not be able to submit the paper, so we have to have soe sort of accounting or a few bad apples will use the leave repeatedly. So basically giving the leave a "serial number" will allow the tracking.

 

Thanks in advance !!

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 ,
Oct 23, 2020 Oct 23, 2020

Copy link to clipboard

Copied

PDF format specs. requires an unique ID number for each PDF file, you should use it instead of reinventing the wheel 😉

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

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 ,
Oct 23, 2020 Oct 23, 2020

Copy link to clipboard

Copied

i looked at that prior to posting, and being honest, it was greek. I am a novice, compared to you guy.... but think of this, I'm a rocket scientist on this stuff to them. i just taught them how to add the signature field, but when i tried to have them add the submit button with it.... i lost them. 🙂 so i know they would not accept hunting that information, oh and those are my superiors..lol

 

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