Amit Gujarathi
Giga Sage
Giga Sage

Hi All,

Hope you are doing fine.
In today's tutorial, we will be looking into one of the most important client-side functions which is getReferecnce.
In this tutorial, we will try to understand in depth what is ServiceNow getRefecrence client-side function is.

Titles of the tutorials
1. What is ServiceNow Client-side APIs
2. What is ServiceNow getRefecrence function
3. What are the best practices to use the getReferecnce function
4. What are the advantages of the ServiceNow getReference function
5. Use case demo

Before we jump into the tutorial let's try to understand what is ServiceNow getReference function
GlideForm - getReference(String fieldName, Function callBack)
Returns the GlideRecord for a specified field.

If a callback function is present, this routine runs asynchronously. The browser (and script) processing continues normally until the server returns the reference value, at which time, the callback function is invoked. If a callback function is not present, this routine runs synchronously and processing halts (causing the browser to appear to hang) while waiting on the server response.

Important: It is strongly recommended that you use a callback function.
Callback function support for ServiceCatalogForm.getReference is available.


Hope you like this video. Please like and subscribe to my channel Technomonk to get such videos in the future.

Regards,
Amit Gujarathi
(Technomonk)

Comments
Tim Kulhavy
ServiceNow Employee
ServiceNow Employee

Hi Amit,

 

I have to point out that getReference is not considered best practice, even with a callback function, as it retrieves the complete record while usually you only need one field or two. The recommended best practice options are g_scratchpad or GlideAjax.

See https://community.servicenow.com/community?id=community_question&sys_id=2d08436ddb1cdbc01dcaf3231f9619bd and https://docs.servicenow.com/bundle/rome-application-development/page/script/client-scripts/concept/client-script-best-practices.html for more information.

 

From docs: "GlideRecord and g_form.getReference() are also available for retrieving server information. However, these methods are no longer recommended due to their performance impact. Both methods retrieve all fields in the requested GlideRecord when most cases only require one field."

Version history
Last update:
‎10-11-2022 02:25 AM
Updated by:
Contributors