Push date and time to a string field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2023 08:28 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2023 08:33 AM - edited 04-13-2023 08:35 AM
Worked in both client and server scripting you can achieve this using:
var unique = "CONTR" + Date.now();
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2023 08:41 AM
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2023 08:45 AM
If you want to use time as you asked for you can use this in a server side script
"CONTR"+new GlideDateTime().getNumericValue()
Output