Copy link to clipboard
Copied
I am using the code below to get date and time stamp on my file but I also want to add serial number with it which is unique to identify it later when I see list of that. Can anyone please help.
// get the current date and time
var d = new Date();
this.getField("UniqueNumber").value = util.printd("yymmdd-HHMMss", d);
Then you need to move the command to the custom calculation script of the field, and adjust it like this:
if (event.target.value=="") event.value = Math.random().toString().substring(2,7) + "_" + util.printd("yymmdd-HHMMss", new Date());
Copy link to clipboard
Copied
Is the serial number a fixed string? If not, how do you want to generate it?
Copy link to clipboard
Copied
Yes it should be a fixed string
Copy link to clipboard
Copied
Then you can do it like this:
this.getField("UniqueNumber").value = "ABCD_" + util.printd("yymmdd-HHMMss", d);
Copy link to clipboard
Copied
Sorry my bad it's not a fixed string.
I have a form in which when user opens the form unique number and date and time stamp should be there in a text field which is read only. When user tries to save it in between and reopens the file, unique number and date and time stamp should not change and he should be able to make changes.
Also when he is trying to fill again from beginning it should generate new unique number with current date and time.
I don't know how is this possible, but was thinking is it can be done by pop up msg or something. I am not sure. Can you please help me.
Copy link to clipboard
Copied
So you want to generate a random number, or something like that?
Also, your other requirements are not very well defined. You need to specify exactly when the value should be updated, and when it shouldn't be.
Copy link to clipboard
Copied
Basically I have a form which will be used by multiple users. When a user open the form A random number should be generated with date and time stamp. This random number & date and time stamp should not change even if user saves this form and reopen it to make changes.
It should only change when user is trying to fill new form.
Also I have a clear form button so I was thinking when user tries to clear the form new number and date and time should be generated and if form is not cleared than random number (which is unique) date and time should remain same
Copy link to clipboard
Copied
How long should this random number be?
Copy link to clipboard
Copied
Use this code to generate a 5-digit random number. It will also only fill in the value once, until the form is cleared:
if (this.getField("UniqueNumber").valueAsString=="")
this.getField("UniqueNumber").value = Math.random().toString().substring(2,7) + "_" + util.printd("yymmdd-HHMMss", new Date());
Copy link to clipboard
Copied
So now what is happening is I have to click on unique number textbox every time I do clear form, than only new number is generated. What I want is when I click on clear button unique number should be automatically displayed
Copy link to clipboard
Copied
Then you need to move the command to the custom calculation script of the field, and adjust it like this:
if (event.target.value=="") event.value = Math.random().toString().substring(2,7) + "_" + util.printd("yymmdd-HHMMss", new Date());
Copy link to clipboard
Copied
Yes this worked.
Also is there any way I can convert date and time stamp to unique serial number (Not random) just like we do in Excel.
Thanks for all the help
Copy link to clipboard
Copied
You can use the getTime() method on a Date object to convert it to a number of milliseconds from a specific moment (the "Epoch time"), like this:
new Date().getTime()
It will return something like "1548446838877".
This value is unique and reversible, ie you can take it and convert it back to a Date object to find out the exact time it represents.
Copy link to clipboard
Copied
How do I do this? Can you please show me steps.
Copy link to clipboard
Copied
Replace this:
util.printd("yymmdd-HHMMss", new Date())
With the code I provided before...
Copy link to clipboard
Copied
Is there any way I can get that number in date_time format. So that number is separated by date and time
Copy link to clipboard
Copied
No... For that you should use the printd method.
Copy link to clipboard
Copied
Hi there, I've used calculations provided. However, calculations work but it sets a default value from the beginning. When I tried sending this document, user(s) receive same number that I see on my preview screen. Do you know if there is any extra configuration that I should be doing?
Copy link to clipboard
Copied
The calculation scripts only execute when the value of a field in the file is changed.
If you want to run the code when the file is opened, for example, then it needs to be moved elsewhere, and also modified.