- 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-17-2025 10:10 PM
were you able to find the solution?
- 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 @terrillc
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 .