GlideRecord getUniqueValue

Colleen
Tera Expert

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.

9 REPLIES 9

MrMuhammad
Giga Sage

Hi Colleen,

getUniquevalue() is documented here - 

https://docs.servicenow.com/bundle/orlando-platform-administration/page/administer/table-administrat...

it is recommended to use getUniqueValue() as it guarantees the string value.

getValue() also returns the string value but calling the property directly [gr.sys_id] can be of type object or string it doesn't guarantee anything. That's why avoid calling property instead use getValue or getUniqueValue() for sys_ids.

See a quick comparison at below link

https://grow.usecoda.com/use-gr-getuniquevalue

Hope that helps!

Thanks,

Sharjeel

Regards,
Muhammad

Thanks for the information.

The unique record identifier page references getUniqueValue as a method of g_form, not GlideRecord.  The information on the CODA page is helpful, but it is not official ServiceNow documentation, as far as I can tell.

I asked about the getUniqueValue GlideRecord method because I was using it in a ATF configuration step script that was returning inconsistent results.  Since I replaced getUniqueValue with getValue('sys_id'), the script has worked correctly. I was therefore looking for some clarity on the getUniqueValue GlideRecord method.

 

There are many methods that are not documented in official documentation but those are widely used and recommended.

It is being used in OOB scripts as well, I just queried the business rules containing getUniqueValue and got 350 OOB BRs. See the screenshot for reference.

find_real_file.png

Maybe it has issues in ATFs only. As, I never used getUniqueValue in ATF so not sure about that. 

 

Regards,
Muhammad

@Colleen 

Do we need a follow up on this or is this answered? If answered. please close the thread by marking the appropriate response as correct and helpful. That will help others looking for the same solution, in the future.

Have a nice day & Stay Safe! 🙂 

Thanks & Regards,

Sharjeel

 

Regards,
Muhammad