Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Adding Control Number to Form

Avatar

Former Community Member
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

Avatar

Former Community Member
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.

Avatar

Former Community Member
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.

Avatar

Former Community Member
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.

Avatar

Former Community Member
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.

Avatar

Former Community Member
Thanks for the help on this. I will review some FormCalc documentation to see how best to do this.

Avatar

Former Community Member
Paul, can you post the script how to generate a random number based on time?



Thanks

Avatar

Former Community Member
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()

Avatar

Former Community Member
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

Avatar

Former Community Member
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).

Avatar

Former Community Member
Paul, how can I include milliseconds into my script above?

Can you help me with this addition please?

Thanks

Avatar

Former Community Member
It does it by default. simply use the FormCalc command like this:



FieldName.rawValue = time()

Avatar

Former Community Member
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

Avatar

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!

Avatar

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?

Avatar

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

Avatar

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.

Avatar

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

Avatar

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.

Avatar

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