What It Does
The getReference() method performs an asynchronous server call to retrieve the complete record referenced by a reference field. Unlike getValue() which only returns the sys_id, this method fetches the entire referenced record with all field values converted to their display representations.
ServiceNow makes an AJAX call to the server, loads the referenced record using the sys_id from the reference field, and processes all field values through their respective display functions. Choice fields get their choice labels, reference fields get their display values, and date/time fields get formatted according to user preferences. The entire process respects ACLs and field-level security.
The callback receives a GlideRecord-like object that behaves similarly to a server-side GlideRecord but contains only display values. You can access fields using dot notation or getValue() methods. If the reference field is empty or the referenced record doesn't exist, the callback receives null. If the user lacks read access to the referenced record, the callback receives an empty object.
The method processes reference fields differently based on their configuration. For table-specific references, it loads the exact record type. For generic references (like Document ID fields), it determines the correct table and loads from there. Extended tables work correctly—a reference to a Hardware record will load the actual CI type (Server, Network Gear, etc.) with all extended fields populated.
Unlike getDisplayValue() which only returns the reference field's display value, getReference() provides access to all fields on the referenced record. This makes it essential for complex client-side logic that needs to examine multiple fields on the referenced record or chain through multiple reference relationships.
When to Use This
Use getReference() when you need to access fields on the referenced record beyond just its display name. Common scenarios include conditional field visibility based on referenced record attributes, populating dependent fields with data from the referenced record, or building complex validation rules that examine multiple aspects of the referenced data. This is particularly valuable in Service Catalog items where user selections in reference fields drive the visibility and validation of other form elements.
Avoid this method for simple display purposes where getDisplayValue() suffices. Don't use it repeatedly in loops or onChange events for the same field—the AJAX overhead becomes significant. For performance-critical scenarios where you need reference data immediately, consider server-side UI Policies or preloading the data using g_scratchpad from a Business Rule instead of making client-side AJAX calls.
This method performs network requests. Use sparingly in onChange events to avoid overwhelming the server with AJAX calls.
Return Value
The method returns void immediately—all meaningful data comes through the callback function. The callback receives a GlideRecord-like object with properties corresponding to the referenced record's fields. All values are display values, meaning choice fields show labels instead of internal values, dates show formatted strings, and reference fields show display names rather than sys_ids.
When the reference field is empty, the referenced record is deleted, or the user lacks read access, the callback receives null. Always check for this condition before accessing properties on the returned object. The object doesn't have all GlideRecord methods—it's a plain JavaScript object with field values, not a full server-side GlideRecord instance.
Enjoying this? Get one deep-dive per week.
Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.
Platform Behavior & Side Effects
- Generates an AJAX request to the server, visible in browser network debugging tools as a call to
/api/now/form - Respects ACLs on the referenced table—users without read access get
nullin the callback - Does not trigger Business Rules, Workflows, or other server-side automation on the referenced record
- Results are not cached—each call makes a fresh server request, making it potentially expensive for repeated calls
- Works in all client-side contexts (Client Scripts, UI Policies, UI Actions) but not in server-side scripts
- Executes asynchronously, so code after the method call runs before the callback executes
- Field-level read ACLs on the referenced table are respected—restricted fields appear as empty values in the returned object