Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Will gs.generateGUID() give unique key everytime or not???

Gaurav Bajaj
Mega Sage

Hi,

I need help on the below scenario.

I am trying to create an incident with use of UI page( can't use a record producer), where i need a custom attachment button.

For the same, i am using the saveAttachment('incident','incident_sysId') method where we need to populate table name and sysid of the current record.

The problem which i am facing is that i need sys_id of the new record which i am going to create with UI page. But then, record is not yet created so i don't have sys_id with me to append in the saveattchment method. So i figured out a way how record producer works, it generates a new GUID everytime and create a record in attachment table with same table sys_id

And then when user submits the Record producer, it captures the same table sys_id and create new record in Incident table with same sys_id.

To replicate same behavior through UI page, we can use gs.generateGUID() method which gives unique key every time, and then once attachment is added, we can create a record with same new sysId, My concern is whether gs.generateGUID() will   always give me unique key   and it would never be as same as any of already created records in incident table because this could lead to a chaos in my case.

Please help in this case if you have any knowledge on it or a better way to implement the same scenario.

Thanks

Gaurav Bajaj

1 ACCEPTED SOLUTION

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Hi Gaurav,



gs.generateGUID will give you always a unique key.



Regards,


View solution in original post

9 REPLIES 9

Chuck Tomasi
Tera Patron

Hi Gaurav,



I cannot speak to gs.generateGUID() because it's not documented anywhere. I'm curious where you got this from? Normally one uses the return result from a GlideRecord insert() method and holds on to that.



That being said, according to the docs - sys_ids (GUIDs) are NEVER reused.



Unique Record Identifier - ServiceNow Wiki


Hi Chuck,



Its pleasure to see a reply from you.


I got this method from glide system api


There is OOB method available..(search for gs.generateGUID() )


Scoped GlideSystem API Reference - ServiceNow Wiki



Thanks


Gaurav


Thank you for the reference Gaurav. I somehow missed that in my search.



I hope that answers your question if GUIDs are unique everytime. The short answer is YES


Thanks Chuck