How to validate UUID value

Supriya25
Tera Guru

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.

5 REPLIES 5

Supriya25
Tera Guru

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');

Supriya25_0-1745337945562.png

 

@Supriya25 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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 .

Supriya25_0-1745344149209.png

Supriya25_1-1745344174973.png

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();

@Supriya25 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader