How to validate UUID value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2025 08:48 AM
Hi All,
Usecase : traceid we are using to traceid the API request end-to end.
When ServiceNow send api-request to get data from Source, during this process if request taking huge time or frequently got 500 or 404 or 400..etc API owners team will check that request at their system based off the traceid which I passed in restapi variable parameter .
Problem here is :
when I use above code to pass UUID format id in traceid variable , that UUID value not reflecting in api-owners system side. but when I put online generated ID in code that value reflecting their end.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2025 08:49 AM - edited 04-22-2025 09:09 AM
below code I have used. it is showing in ServiceNow outbound http logs request header{traceID:b6056108-1ba05-4cfc-96c8-c2e3b7ebbb42, but not reflecting to API owners side in their system.
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);
var restMessage = new sn_ws.RESTMessageV2('CustomeData', 'customerProfile');
restMessage.setStringParameterNoEscape('traceID', uuidValue);
but when I use online generated one it got passed successfully and reflecting on API owners system. why this is happing like this.
var restMessage = new sn_ws.RESTMessageV2('CustomeData', 'customerProfile');
restMessage.setStringParameterNoEscape('traceID', 'f5086108-1a05-4cfc-96c8-f2e3b7ebbf42');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2025 09:24 AM
UUID format has 8-4-4-4-12 characters
Did you check with 3rd party team what format they accept?
Maybe they are accepting some other UUID format with some restrictions in that format
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-22-2025 10:54 AM - edited 04-22-2025 10:58 AM
They confirmed that UUID format is 8-4-4-4-12
I have been asked to try Online Generate UUID in my code for testing once and test it once. I copied the code and tried in my script
restMessage.setStringParameterNoEscape('traceID', 'f5086108-1a05-4cfc-96c8-f2e3b7ebbf42');
successfully UUID code reflecting in 3rd party system without any hassles , it's really wondering .
surprise part is ServiceNow generating ID not reflecting and Online UUID reflecting .
I checked with Other consumers who are using the same API's , they said they are using below one in their code , it is successfully reflecting in 3rd party system.
string traceId = UUID.randomUUID().toString();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2025 09:31 PM
it's surprising, even the script within ServiceNow is generating in the same format 8-4-4--4-12
Share the complete script along with REST Message and the logic to generate UUID
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