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

Adding Control Number to Form

Not applicable
I am new to LiveCycle Designer. Is there anyway to add a control number to forms? I would like to have it so that when the form is submitted, the form number will increase by one. Any suggestions?
24 Replies
yodadobe
Level 6
Level 6
There are many ways to do it. One would be a webservice call in the pre-submit or initialize, depending on when you want it. I add a number on the back end after being submitted.
Not applicable
I am not sure what a webservice call is. By reading online documentation I tried using a variable as a place holder to increase the number by one each time the form is submitted, but that does not seem to work.
yodadobe
Level 6
Level 6
A variable in the form can only keep track of data within that instance. If 5 people open it, all 5 will start at the same number. If the form is opened from disk by a single person, submitted, closed and reopened, it starts at the same number again. You have to have some common point of keeping track of the number. So you have to make a server call, webservice, database, etc. It cannot be done within the scope of a stand alone PDF form.
pguerett
Level 10
Level 10
If you do not have access to an external source you could generate a random number based on time but that would not be a sequential number but you can guarantee a unique number.
Not applicable
Thanks for the help on this. I will review some FormCalc documentation to see how best to do this.
Not applicable
Paul, can you post the script how to generate a random number based on time?



Thanks
pguerett
Level 10
Level 10
Simply use the FormCalc command Time(). It will return the # of milliseconds since the epoch. I put this command on the initialize evet of the field that I want the number in.



$ = Time()
Not applicable
Paul, do you mean something like this:



$.rawValue = (Math.floor((new Date()) / 1000) ) %1000000000;

My question it is the number will generate will be guarantee a unique number?

What about if two users open the form at the same time?



Thanks again
pguerett
Level 10
Level 10
It woudl have to be at exactly the same time (if you include milliseconds in your time then you can be quite certain the the numbers will be unique).
Not applicable
Paul, how can I include milliseconds into my script above?

Can you help me with this addition please?

Thanks
pguerett
Level 10
Level 10
It does it by default. simply use the FormCalc command like this:



FieldName.rawValue = time()
Not applicable
Paul, there is any way to freeze the field text with the unique number, so any time we reopen the form, the number will remain the same?



Thanks
Jono_Moore
Level 10
Level 10
You can also use a UUID (Universally Unique Identifier)



Formcalc:

$.rawValue = Uuid(1)



Which results in a string like this:

340e4465-559a-4fbd-bac2-455a7ac85248



I've just been playing around with this function recently but the resulting string is rather unwieldy. I like the idea of using Time(), it gives an easier-to-deal-with number as a result - thanks Paul!
Jono_Moore
Level 10
Level 10
Actually, I noticed that Time() really only returns the number of milliseconds in the current day so I tried:

$ = Date() * 86400 + Time()

To get the actual milliseconds since epoch (86400 milliseconds in a day).



But that didn't work out quite right (math isn't my best attribute ;).



Any ideas?
Niall_O_Donovan
Level 10
Level 10
Hi Jono,



86400000 (8.64e+007) milliseconds in a 24 hour period. Using your script you end up with a 13 digit reference.



Niall
Jono_Moore
Level 10
Level 10
Thanks Niall, forgot those pesky zeroes...



Still not working correctly though - how would I combine time() and date() to get the proper number of milliseconds? Even with the correct number of zeroes it isn't working correctly.
Niall_O_Donovan
Level 10
Level 10
hmmm,



Seems to work here...



$ = Date() * 84600000 + Time()



I tried it longhand as well and got the same answer... The next problem is getting it to stay static on reopening. I am thinking of getting a convert to string script on the submit button and generating a barcode...



Enough for now 😉



Good luck,



Niall
Jono_Moore
Level 10
Level 10
The number that comes out isn't correct, it's 13 digits and if I put it into a time converter it comes out as: Tue Oct 27 2076 08:45:05 (should be today's date, and time is wrong).



http://www.esqsoft.com/javascript_examples/date-to-epoch.htm



Ah well, not really important except to figure out what I'm doing wrong math-wise. Maybe I'll try mucking with javascript.



Or maybe just the time in milliseconds for the day is enough, but I thought getting the full amount of milliseconds since epoch would be better - that way there's almost zero chance of a collision.
Niall_O_Donovan
Level 10
Level 10
Hi Jono,



The issue may be that "LiveCycle Designer ES defines day one for the epoch for all date functions as Jan 1, 1900".



The website you referred to has the following statement "Epoch has a few meanings (see also http://dictionary.reference.com/search?q=epoch). The definition that we'll use is "0" in computer time. While there are folks who will argue this, for our purposes, this "0" time on our calendar was January 1, 1970 00:00:00 GMT"



That would explain why the answer is approximately 70 years off!!



I think I will use your script (thanks!), but truncate the answer to the last 8 digits.



Good luck,



Niall