- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 09:01 PM
Hello Community,
I'm trying to understand how the getReference() function works in ServiceNow, especially when used in client scripts. I would appreciate any guidance or examples that can help clarify its functionality
- I'm working with a reference field (e.g., caller_id on the Incident form).
- My goal is to retrieve additional fields from the referenced record (e.g., email or department) when the reference field is populated.
What I've Tried:
I’ve implemented the getReference() function in an onChange client script, but I'm not entirely sure if I'm using it correctly or how to handle cases where the referenced record is not found.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 09:31 PM
Hi @saikumar2612 The getReference() method is used in client scripts to fetch a GlideRecord object from a reference field on a form. Reference fields are fields that point to records in other tables. The getReference() method allows you to retrieve the referenced record and access its properties.
Have a look at this thread https://www.servicenow.com/community/developer-forum/what-is-use-of-getreference/m-p/1791072
https://servicenowguru.com/client-scripts-scripting/gform-getreference-callback/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 09:31 PM
Below link will help you to get a better understanding of getReference() :
Please note that using getReference is not considered a best practice, even with a callback function, as it retrieves the complete record while usually you only need one field or two to work with. The recommended best practice option is GlideAjax.
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 09:31 PM
Hi @saikumar2612 The getReference() method is used in client scripts to fetch a GlideRecord object from a reference field on a form. Reference fields are fields that point to records in other tables. The getReference() method allows you to retrieve the referenced record and access its properties.
Have a look at this thread https://www.servicenow.com/community/developer-forum/what-is-use-of-getreference/m-p/1791072
https://servicenowguru.com/client-scripts-scripting/gform-getreference-callback/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 09:31 PM
Below link will help you to get a better understanding of getReference() :
Please note that using getReference is not considered a best practice, even with a callback function, as it retrieves the complete record while usually you only need one field or two to work with. The recommended best practice option is GlideAjax.
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 10:45 PM
Thank You

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 09:42 PM
Hi there,
Why asking about getReference? This is a poor method. Go for superior methods, like GlideAjax with getXMLAnswer.
- 2020-01-10 - Article - Client Side Scripting: Go for GlideAjax (with getXMLAnswer)!
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field