- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2021 02:54 PM
Hi,
What is use of getReference().
Can anyone please give me one example for this.
Regards,
Nivedita
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2021 03:23 PM
Hi Nivedita,
You can see an example here on the Docs site.
You use it in a client script to retrieve the entire record of a reference field/variable, then you can use another column on the same record in the script to setValue of another field/variable, etc.
Here's an example which sets the value of a location variable to the location that is on the user record of the requested for.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var userref = g_form.getReference('requested_for', userLookup);
function userLookup(userref){
g_form.setValue('location', userref.location.toString());
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2021 03:23 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2021 03:23 PM
Hi Nivedita,
You can see an example here on the Docs site.
You use it in a client script to retrieve the entire record of a reference field/variable, then you can use another column on the same record in the script to setValue of another field/variable, etc.
Here's an example which sets the value of a location variable to the location that is on the user record of the requested for.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var userref = g_form.getReference('requested_for', userLookup);
function userLookup(userref){
g_form.setValue('location', userref.location.toString());
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2021 03:25 PM
It returns a gliderecord object of a given record. Note, don't use it, it's awful on performance.
Client Side Scripting: Go for GlideAjax (with getXMLAnswer)!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2021 03:27 PM
- The functionality is about is the g_form getReference callback API
- It is a ServiceNow Client Side Scripting
- It’s extremely useful, but can also be a huge performance killer if not used correctly
-
Returns a Reference Object's record client-side
- Request a record from the database
- Requested record returned from the database
- Execute logic after the object returns from the server
- It runs "asynchronously" when used with a callback function
- If callback function is not used, it executes a "synchronous" call
- Generic syntax is g_form.getReference()
Example: without a callback (Not Recommended because it is a synchronous call and might hamper system usability)
When: onChange Field: caller_id function onChange(control, oldValue, newValue, isLoading) { var caller = g_form.getReference('caller_id'); if (caller.vip == 'true') alert('Caller is a VIP!'); }
**Synchronous getReference() method calls lock the form until the requested record is returned from the database.
Example: with a callback (recommended, it is a asynchronous call and should not hamper system usability)
When: onChange Field: caller_id 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!'); }
**Asynchronous execution allows users to continue using the form while the method call executes.
--> Please mark the answer helpful if it has helped you and mark the answer as correct