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

Need help with random reference number

New Here ,
Aug 24, 2017 Aug 24, 2017

Copy link to clipboard

Copied

Hi. I am currently making a time sheet in Adobe Acrobat DC which requires a unique reference number everytime a new person fills it out and sends it in. I have tried several things and besides setting up a database the pdf can connect to and extract a new number from which wasnt used, this is what i came up with.

I made a button you can click on "LøbenummerKnap" (sorry for the danish), when clicked it fills out my field with a new random number which is based on time. And it works.

My problem is that i need it to be as short as possible but still guaranteeing the next number is unique to what have bin given earlier.

This is my code on the button:

var d = new Date();

//Divide by 100 to get miliseconds

this.getField("Løbenummer").value = Math.floor(d / 100);

So every milisecond a new number is assigned to my "Løbenummer" field if the button is pressed. The odds of anyone clicking the button at the same milisecond is very very unlikely, but my boss still wants the number to be shorter for further processing by the company.

Is it possible to make the output shorter whitout changing the fact the people wont get the same number?

TOPICS
Acrobat SDK and JavaScript , Windows

Views

548

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 , Aug 24, 2017 Aug 24, 2017

To access a local DB you would have to use LCD. If the values are accessed via a web-service it can be done in an Acrobat form.

You will need to study the Net.HTTP object to learn how to do it.

Votes

Translate

Translate
Community Expert ,
Aug 24, 2017 Aug 24, 2017

Copy link to clipboard

Copied

Is it possible to make the output shorter without changing the fact the people wont get the same number?

By definition, no. The shorter you make the number the higher the chance of two people getting the same one. I would actually recommend you use real random numbers, not ones based on the date, for better results. That would minimize the chances of two people getting the same number (since it won't matter when they open the file), but it won't change the fact that the shorter the number, the higher those chances are. If you use 4 digits it will be one in 10000, if you use 6 digits it's one in a million, etc.

Look into the Math.random() method for that.

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 ,
Aug 24, 2017 Aug 24, 2017

Copy link to clipboard

Copied

I figured this was the case, i might just end up setting it up to connect to a database.

Why would 'real random numbers' give me a better result? As i see it 'real random numbers' are just that. Random. Which makes it possible for 2 persons to get the same number eventually - were the method i use now calcs the miliseconds since a date in 1970 (as far as i understand from the thread i got inspired by) and gives the number based on that. Only way for 2 people to get the same number is by pressing the button in the same milisecond, which ofcourse also is possible - but highly unlikely.

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 ,
Aug 24, 2017 Aug 24, 2017

Copy link to clipboard

Copied

You can only connect a PDF form that was created using LiveCycle Designer to a DB, not one created in Acrobat.

If you're using the full number then yes, you would only get duplicates if two people open the file at exactly the same millisecond, but you're removing digits from it... So if you remove 3 digits (from the right side) you're down to seconds. Remove 5 digits (down to 6 from the original 13) and you're now down to minutes, etc. It's not that unlikely that two people will open the file during the same minute, I think.

If you're using six digits it's better to use a random number, with a 1/1,000,000 chance of getting a duplicate, then betting that two people won't open the same file during the same minute, it seems to me.

Also, the more people who use the file the higher your chances of getting duplicates (since they're all likely to open it using specific times of the day), whereas with random numbers the chance of getting a duplicate are purely mathematical.

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 ,
Aug 24, 2017 Aug 24, 2017

Copy link to clipboard

Copied

Didnt know the LiveCycle designer thing, seeing as most guides/threads about this are years old and not regarding Adobe Acrobat Dc. But that sucks.

Im removing 2 digits from the number currently, which i figured was miliseconds. I can see its called a decisecond (1 tenth of a second) which is fine. The action happens when they click the button so even if people would open the document around the same time, the odds of 2 people clicking the button at the same decisecond is very low.

But i see your point.

So there is no way for me through Adobe Acrobat Dc to get a field to be filled with a 100% guaranteed unique number?

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 ,
Aug 24, 2017 Aug 24, 2017

Copy link to clipboard

Copied

So there is no way for me through Adobe Acrobat Dc to get a field to be filled with a 100% guaranteed unique number?

Not unless you use a web-service to provide a unique number to the file (based off a DB), but that is quite complicated.

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 ,
Aug 24, 2017 Aug 24, 2017

Copy link to clipboard

Copied

But i would have to redesign my form with LiveCycle Designer to achieve this if i understand your previous post right, correct?

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 ,
Aug 24, 2017 Aug 24, 2017

Copy link to clipboard

Copied

To access a local DB you would have to use LCD. If the values are accessed via a web-service it can be done in an Acrobat form.

You will need to study the Net.HTTP object to learn how to do 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
New Here ,
Aug 24, 2017 Aug 24, 2017

Copy link to clipboard

Copied

LATEST

Got it, thanks. Just wanted to make sure it was possible before i start working on it.

But thanks for the fast & great responses!

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