GlideRecord getUniqueValue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2020 03:06 AM
Is getUniqueValue a valid GlideRecord method? It is not listed in the GlideRecord documentation, but can be selected from the intellisense menu in a ServiceNow script editor.
If gr is a GlideRecord object, Is it better to use gr.sys_id or gr.getValue('sys_id') to retrieve the sys_id as a string? When I have referenced the sys_id property in a workflow script it seems to return an object rather than a string.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2020 03:21 AM
Hi Collen,
Yes, it can be termed as one of methods of GlideRecord.
For question
'If gr is a GlideRecord object, Is it better to use gr.sys_id or gr.getValue('sys_id') '
better use gr.getUniqueValue() as it will always return output in string. Refer link for a check.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2020 03:27 AM
Hi Colleen,
Yes you can use "getUniqueValue" an OOB function to retrieve a sys_id of a record.
gr.getValue('sys_id') will also return the sys_id.
But if you are using "gr.sys_id" you should use toString() function like this "gr.sys_id.toString()"
Any of the above 3 ways can be used to retrieve the sys_id.
Kindly mark my answer as Correct and Helpful based on the Impact
Regards,
Alok
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2020 04:01 AM
Hi Colleen,
ServiceNow and many developers use different supported functions for this:
- gr.getUniqueValue();
- gr.sys_id.toString()
- gr.sys_id + '';
- gr.getValue('sys_id');
All return the sys_id as a string and will work. They are all used throughout the system.
The gr.sys_id is just a 'pointer' to the sys_id field, which will not always be interpreted as a string.
Hope this helps! 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2020 04:08 AM
Hi Colleen,
Both getValue() and getUniqueValue() will return a value from the GlideRecord upon which they're called.
getUniqueValue() accepts no arguments, and simply returns the primary key (the sys_id) of the record.
getValue() on the other hand, can return the value from any table column (including sys_id). It accepts one argument - a field name, and will return the value therein.
I believe getUniqueValue() is a best way to get unique id (sys_id) of the record from server side and client side scripting both.
If my answer helped you in any way, mark answer as helpful and correct.
thanks and regards,
Megha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2020 03:50 PM
Hi Colleen,
Hope you are doing well.
Is your question resolved? Or do we need to follow-up on this?
Please mark the answer as correct if it solves your question. This will help others who are looking for a similar solution. Also marking this answer as correct takes the post of the unsolved list.
Thanks.
Kind regards,
Willem