Is it possible with a LiveCycle form that is not connected to a database, to automatically have a unique sequential form number populate a textfield when the form is opened? This would be the number that identifies that version of the form.
Solved! Go to Solution.
Views
Replies
Total Likes
I've used this script for a bunch of forms.
It uses the date to generate a mostly unique number — forms would have to be opened at exactly the same time to get a collision.
Put it on the Initialize event of a text field. It also checks to see if the field already has a value and if it does it leaves the value as-is, so if someone saves the form it keeps the same number. You can remove the else statement if you're not worried about that.
if (this.rawValue == null) {
var d = new Date();
//divide by 1000 to get seconds and trim decimals
this.rawValue = Math.floor(d / 1000);
} else {
this.rawValue = this.rawValue;
}
Views
Replies
Total Likes
No errors in console. I will recheck the script. Will take a while.
Views
Replies
Total Likes
Is it possible to tie this script to an object - like when a radio button is chosen and have it only run once even if they change their choice?
Views
Replies
Total Likes
I tried running the script when entering a text field. Works okay - but then I exit the textfield and re-enter and the form number field goes to null (blank) - why?
This is the script I am using...
if (Company.ARnumber.rawValue == null) {
var d = new Date();
//divide by 1000 to get seconds and trim decimals
Company.ARnumber.rawValue = Math.floor(d / 1000);
} else {Company.ARnumber.rawValue = this.rawValue;
}
Views
Replies
Total Likes
Yeah you can put it on a button or the like. You just need to change the references to "this" to the name of the field.
if (fieldName.rawValue == null) {
var d = new Date();
//divide by 1000 to get seconds and trim decimals
fieldName.rawValue = Math.floor(d / 1000);
} else {
fieldName.rawValue = fieldName.rawValue;
}
Views
Replies
Total Likes
You need to change the last "this" reference to the name of the field.
Views
Replies
Total Likes
I found the problem - in the last line of script I did not change "this" to the name of the form number field. I am sorry to have caused you all this trouble.
Views
Replies
Total Likes
No problemo!
Views
Replies
Total Likes
CAN I MAKE A BUTTON THAT ABLE TO REFRESH THAT CODE IN THE FIELD
SO I CAN GENERATE A NEW NUMBER EVERY TIME I PRESS THAT BUTTON ?
Views
Replies
Total Likes
Hi Abduzer, you would just put the code on the Click event of a button.
And if you always want a new number and don't care if the field already has a value then you just need:
var d = new Date();
fieldName.rawValue = Math.floor(d / 1000);
Views
Replies
Total Likes
This is a great script. I am trying to trim off 4 digits from the left side and having no luck. Would you be able to help me? Thanks!
Views
Replies
Total Likes
Give this a shot. I was getting errors with substring() until I realized it wasn't getting a string.
var d = new Date();
var t = Math.floor(d/1000).toString();
TextField1.rawValue = t.substring(4);
Views
Replies
Total Likes
THANKS! It works perfectly! You are awesome!
Views
Replies
Total Likes
First. I know NOTHING about javascript.
I've been able to limp along following your instructions... and THANK YOU.
But... I cannot get the "Invoice Number" to save and send when attaching it to email.
What am I doing wrong?
Views
Replies
Total Likes
Please help - I can not figure this out. I need a field at the top of my form to generate a unique number to identify the request.
I would like my form to generate the field based on the date of the request, but I might have more than one request a day... so for example a request generated in May of 2017 would be 2017-05-#### (the ### being the unique numbers)
How do I do this?!?!?
Views
Replies
Total Likes
Without connecting your form to a database, the form has no way of knowing how many have been created in a particular day. Therefore, the only suggestion I can give you is to use today's date followed by the time formula in this post. The time formula is ten digits long and is a rounded off number but always unique.
Good luck!
Views
Replies
Total Likes
Hi Don,
Thanks but it still doesn't seem to be working for me. This is what I have in the script box:
form1.#subform[0].Request::initialize - (FormCalc, server)
var d = new Date():
request.rawValue = Math.floor(d/1000).toString();
request.rawValue = t.substring(4);
what am I doing wrong? When I preview the PDF - the Request # field is still blank...
Views
Replies
Total Likes
In JavaScript:
if (Company.ARnumber.rawValue == null) {
var d = new Date();
//divide by 1000 to get seconds and trim decimals
Company.ARnumber.rawValue = "AR" + Math.floor(d / 1000)
} else {Company.ARnumber.rawValue = Company.ARnumber.rawValue;
}
Views
Replies
Total Likes
Great I got it to work - thank you. How would I connect it to a database to generate sequential numbers based on the year?
so the form's unique ID would be "IR-2017-001" and then "IR-2017-002" when the first form was printed and saved
thank you for all your help!! I don't get scripting at all!!!
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies