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

Let me know if that answered your question. If so, please mark it as correct so that others with the same question can find it quickly in the future and that it gets removed from the Unanswered list. Thank you


sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Hi Gaurav,



gs.generateGUID will give you always a unique key.



Regards,


Hi Sergiu,



Thanks for the reply.


My concern is that it shouldn't match the already created records or the records going to be created by other means because i am going to create new incident record with it.


Every time you call gs.generateGUID you will get a unique key, so from that point of view you should not problems.



Regards,


Jayanth_aylam
Tera Contributor

Hi Gaurav,

 

I have the similar situation, How can I assign GUID to the sys_id of the record which is yet to be created.

Please help me in this scenario.

Thanks

Jayanth