Push date and time to a string field

Nic Omaha
Tera Guru

Hello, I am trying to generate a unique ID in a string field on a catalog item. What I would like to populate it with is 

"CONTR" +" current date time" in a string, that way it will always be unique. So for example 

 

CONTR04132023102731

 

Any thoughts on how this could be done? Im also open to other ways to set the string field to CONTR + unique number. 

 

 

3 REPLIES 3

Prince Arora
Tera Sage
Tera Sage

@Nic Omaha 

 

Worked in both client and server scripting you can achieve this using:

 

var unique = "CONTR" + Date.now();

 

PrinceArora_0-1681400105326.png

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact. 

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

You can use the Number maintenance table. The same way it generates Incident / Change number etc., it will be unique and you can give a prefix too. 

Check this: Record numbering (servicenow.com)

 

 

-Anurag

If you want to use time as you asked for  you can use this in a server side script

"CONTR"+new GlideDateTime().getNumericValue()

 

Output

AnuragTripathi_0-1681400752566.png

 

-Anurag