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,212 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2024 01:06 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 a GlideRecord for a record that is referenced in a field on another record. - It is useful when you need to access fields from a referenced record, without having to do a separate GlideRecord query. - It can be used in both client-side and server-side scripting. - It is a synchronous call, which means it will wait for the database operation to complete before continuing with the script execution. 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, the getReference() method is used to retrieve the display value of the caller_id field from the incident record with number 'INC0010001'. The caller's name is then logged to the system log.