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,191 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2022 12:58 AM
Performance impact is the reason. This article covers it well:
Regards
Paul

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-05-2021 11:29 AM
Hello
Can you please show where ServiceNow is saying that getReference() should no longer be used? I'm thinking based on this API function that it's FINE TO USE, as long as you specify a callback function with it:
Thoughts?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2022 11:58 AM
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
var abc = g_form.getReference('request_for', currentUser1);
return;
}
function currentUser1(abc) {
g_form.setValue('mobile_phone', abc.mobile_phone);
g_form.setValue('manager_approval', abc.manager);
}
//Type appropriate comment here, and begin script below
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2024 01:30 AM
The getReference() method in ServiceNow is used to retrieve a single GlideRecord referenced in a field. It is a powerful method that allows you to access data from related records without having to do a separate GlideRecord query. Here are some key points about getReference(): - It is used to retrieve the data from a referenced field in a record. - It allows you to access fields from a referenced table. - It is a method of the GlideRecord class. - It can be used in server-side scripting. - It is useful when you need to access data from a related record without doing a separate GlideRecord query. Here is a sample code snippet using getReference(): javascript var incidentGR = new GlideRecord('incident'); incidentGR.get('number', 'INC0010001'); var caller = incidentGR.caller_id.getDisplayValue(); gs.info(caller); In this example, 'caller_id' is a reference field on the 'incident' table. The getReference() method is used to get the display value of the caller_id field. nowKB.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2024 05:17 AM
The getReference() method in ServiceNow is used to retrieve a single GlideRecord referenced in a field. It is a powerful method that allows you to access data from related records without having to write a separate GlideRecord query. Here are some key points about getReference(): - It is used to retrieve a GlideRecord for a reference field. - It allows you to access fields from a referenced record in a single line of code. - It is often used in business rules, script includes, and other server-side scripting. - It can be used to perform operations on the referenced record, such as updating or deleting it. - It is a synchronous operation, meaning it will block other operations until it completes. Here is a sample code snippet using getReference(): javascript var incidentGR = new GlideRecord('incident'); if (incidentGR.get('number', 'INC0010023')) { var callerGR = incidentGR.getReference('caller_id'); gs.info('Caller Name: ' + callerGR.name); } In this example, getReference('caller_id') retrieves the GlideRecord for the user record referenced in the 'caller_id' field of the incident. This allows you to access the 'name' field of the caller directly.