What is the use of getReference()?

ishankaggarwal
Tera Contributor

What is the use of getReference()?

17 REPLIES 17

Shishir Srivast
Mega Sage

you can use the getReference() to glide that particular record from client side and access the related record of that Glide Object, you can find the more details here: GlideForm - Client


Uncle Rob
Kilo Patron

GlideForm - Client



Returns the GlideRecord for the field (must be a reference field) you specify in the parameters.


Rajesh Mushke
Mega Sage

getReference gets the record used in another reference field. For example you have the Caller ID (reference to the sys_user table) and with getReference, you will retrieve the User record and save this as a gliderecord into a variable. The main reason to use this function is to get more information from the referenced record.



Since this is used client side, it IS a call to the server which may impact performance if used too heavily.



Example:


var gr = g_form.getReference('caller_id');


alert('Caller Email is: ' + gr.email);



Since this is a server call, as already said above, I would recommend using the callback feature (new in Aspen):


var caller = g_form.getReference('caller_id', doAlert); // doAlert is our callback function



function doAlert(caller) { //reference is passed into callback as first arguments


alert('Caller Email is: ' + caller.email);


}



Please refer:


Client Script Examples — ServiceNow Elite





Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

this is one of the best explanations of getReference that I have come across.