getReference Function use

ravi154
Giga Contributor

can anybody explain me how getReference function works in service now ?

3 REPLIES 3

narinder_guru
Kilo Contributor

this is used on client side script, for example, in order to get a value from the record in a reference field, you would need to var cmdb = g_form.getReference(cmdb), cmdb.name....


Oliver D_sereck
Giga Expert

Hi Ravi,

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);
}

With the Callback, you have no real performance impact as the UI doesnt wait for the answer to be returned and so block the User from working further.

WIKI Reference:
http://wiki.service-now.com/index.php?title=GlideForm_%28g_form%29#getReference

Cheers,
OD


ravi154
Giga Contributor

thanks every one for the reply