Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Need to create a unique ID for a form...

Avatar

Level 4

I have a form that I need to have a unique ID generated when the form is first opened, and stays the same once saved. I thought using the date/time would work, e.g.; 01012015012556 created from the date/time of 01/01/2015 01:25:56, but can't figure out how to get it to display properly. It can't be a random number just in case it happens to generate the same number. Any ideas? I'm using LiveCycle Designer ES2

1 Accepted Solution

Avatar

Correct answer by
Level 10

if ($.isNull) then


     $ = UUID(1)


endif




View solution in original post

7 Replies

Avatar

Level 10

Hi there,

using the date function is your best shot, especially if it's when the form is open at first.

you have the choice of using each functions of a date to create your own UID or use the getTime() function

Hope this help!

Avatar

Level 10

Hi,

another way would be the UUID() Method in FormCalc that will — as stated in the FormCalc reference — return a

The script


$ = Uuid(1)


fills a text field with something like 0e611f47-0eac-41a7-aee5-578c43a61798

Avatar

Level 4

The only problem with the UUID method, and I'm sure there is a way to fix this, is that every time I open the document, even after saving, the UUID changes. And with the JavaScript, I can't get it to work at all. I've tried it in the docReady, form:ready, and layout:ready, none of them seem to work.

Avatar

Correct answer by
Level 10

if ($.isNull) then


     $ = UUID(1)


endif




Avatar

Level 4

I do have one question, if the form is submitted via a submit button, will the UUID stay the same when received? It would need to stay the same no matter if it is submitted or saved.

Avatar

Level 10

Hi there,

My curiosity was too high to not test the Uuid function of Formcalc as its result doesn't look like a unique id to be generated and considered unique!!

I've made a small test with 1000 samples of this function to see if there could be a leak with duplicates.. There was no duplicate in that case..

But to make sure I've made a test with 100,000 samples and actually found duplicates more than once, as you said at least extremely like a unique id but it still can create duplicates unfortunately

I've also noticed that it is not rotating through time, which would create a unique id depending on the milliseconds in a second or minutes/hours, it can create duplicates whenever but in a small margin of error as I had 8 duplicates in 100,000 samples and the duplicates were starting to be generated more and more frequently...

I don't think a form would be used over 10,000 times to have that many unique ids, but I don't think using this method is good idea, because it could generate a duplicate at any time...

Avatar

Level 10

Hi there,

with the code given by radzmar it should never change the uid given when submitted or saved, the if statement is making sure that it holds a unique id before it assigns one to the form.

Also, you would have to make sure that your reset data button, if you have one of course, does not reset your uid... otherwise it will create another uid once it is null..