- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2025 07:00 AM
Hi All,
Please help me how to validate UUID format in Server side script
below script always returning "Not Valid" .
var uuidValue= gs.generateGUID();
uuidValue=uuidValue.replace(/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/ "$1-$2-$3-$4-$5");
var uuidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
if (uuidRegex.test(uuidValue)) {
gs.info('Valid');
} else {
gs.info('Not Valid');
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2025 08:38 AM
try this
var sysId = '8bafe2e4db072150966c676ed396194c'; // Replace with your sys_id
function convertSysIdToUUID(sysId) {
if (sysId.length !== 32) {
gs.info('Invalid sys_id length');
return null;
}
return sysId.replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, '$1-$2-$3-$4-$5');
}
var uuidValue = convertSysIdToUUID(sysId);
gs.info('UUID: ' + uuidValue);
Output:
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2025 08:11 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2025 10:08 PM
This is not in UUID format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2025 06:36 AM - edited 04-21-2025 07:16 AM
Hi
is it NOT UUID format ? please let me know if something wrong happing here.
var sysId = gs.generateGUID(); function convertSysIdToUUID(sysId) { if (sysId.length !== 32) { gs.info('Invalid sys_id length'); return null; } return sysId.replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, '$1-$2-$3-$4-$5'); } var uuidValue = convertSysIdToUUID(sysId); gs.info('UUID: ' + uuidValue); gs.info('UUID: ' + isUUID(uuidValue)); function isUUID ( uuid ) { var s = "" + uuid; s = s.match('^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$'); if (s === null) { return false; } return true; }
*** Script: UUID: 1ba32558-8301-2210-769a-c020feaad329
*** Script: UUID: true
Could you please check above script once .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2025 08:11 AM
I already answered your question
I informed how to convert sysId to UUID format
Why are you trying to validate it again?
Your task is simply generate random sysId, convert to UUID format and include in API for 3rd party team
it's like you are performing 2+2=4 via script and then again validating if 2+2=4 or not
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2025 09:44 AM
Yes, I good.
I thought of if any additional validations need to be covered over there.