What is the use of getReference()?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2018 08:34 AM
What is the use of getReference()?
- 133,192 Views

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2018 08:37 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2018 08:37 AM
Returns the GlideRecord for the field (must be a reference field) you specify in the parameters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2018 09:25 AM
Hey Ishank,
GlideForm - getReference(String fieldName, Function callBack)
Returns the GlideRecord for a specified field.
If a callback function is present, this routine runs asynchronously, and browser (and script) processing will continue normally until the server returns the reference value, at which time the callback function will be invoked. If a callback function is not present, this routine runs synchronously and processing will halt (causing the browser to appear to hang) while waiting on a server response.
Callback function support for ServiceCatalogForm.getReference is available.
Name | Type | Description |
---|---|---|
fieldName | String | Name of the field. |
callBack | Function | Name of the call back function. |
Returns:
Type | Description |
---|---|
GlideRecord | The GlideRecord object for the specified field. If the specified reference cannot be found, then it returns an initialized GlideRecord object where currentRow = -1 and rows.length = 0. |
function onChange(control, oldValue, newValue, isLoading)
{
var caller = g_form.getReference('caller_id', doAlert); // doAlert is our callback function }
function doAlert(caller) { //reference is passed into callback as first arguments
if (caller.vip == 'true')
alert('Caller is a VIP!');
}
Please Refer:
GlideForm - Client
Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2018 09:29 AM
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