These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Create Serial Number Using Date & Time Functions

BigEd
Registered: Jan 31 2010
Posts: 6
Answered

I am very light on Javascript and I am trying to create a form serial number that will be made up from the system date and time with the following format "YYYYMMDDHHMM". This would execute when the form is loaded. At the moment I am using a Text Field in Acrobat Live Cycle Designer

I sure would appreciate any help.

Thanks,
BigEd

My Product Information:
LiveCycle Designer, Windows
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Hi,

you can use FormCalc in the calculate event of the text field, to do this.
if ($.rawValue==null)then$.rawValue = Concat(Num2Date(date(), "DDMMYYYY"), Num2Time(time(), "HHMM"))else$.rawValueendif

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

BigEd
Registered: Jan 31 2010
Posts: 6
Thank you radzmar for the code. It works just great. I assume that the serial number will be placed on the form when it is first loaded and it will remain the same once you fill in data and then reload. I also noticed that you can't reset it with a reset button.

I am looking forward to learning more about Javascript for Designer as I can see how useful it is.

Thanks again,
BigEd
BigEd
Registered: Jan 31 2010
Posts: 6
radzmar,

I have been having a little problem with the way in which the code works. I save the form in Designer and when I first bring it up in Acrobat the code executes fine, however when I try to provide rights management and save the file it retains the calculated S/N. Is there a way I can execute the code when the user clicks the field or should I use another object? I really appreciate that you took the time to answer.

If you can, please advise me so I can finish this form.

Thank you,
BigEdI resolved this problem by using the "enter" command in formcalc instead of calculate. Now when I load an empty form I can click the S/N field and it puts the calculated S/N in and it stays there from then on. Thanks again for all the help.

BigEd
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Hi,

you have to do the following procedure.
Open the finished form in Acrobat.
The textfield will be filled by the script.
Clear the value of the text field and then enable the Reader rights.
Close the Reader enabled form and reopen it.
The script should now work as expected.

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

BigEd
Registered: Jan 31 2010
Posts: 6
Thanks again redzmar, I will try that approach. One thing I noticed was that I was unable to clear the field once it had run. I will try again.

Thanks for your help,
BigEd
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Oh, of course you can't change it, because I told you to use the calculate event.
Sorry, but this case will not allow to change the field.
You better put the script above in the form:ready event. :-)

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

alfatiger
Registered: Aug 20 2010
Posts: 1
Hi Radzmar,
I pasted your code in the Javascript editor of the "Custom calculate script:" option of the Text Field Properties and got a "syntax error 3: at line 4" which highlights the line $.rawValue