The getRefRecord() method retrieves the complete GlideRecord for a reference field using the query ServiceNow already executed when loading the parent record. Dot-walking like current.assignment_group.name triggers individual field lookups for each property access, but getRefRecord() gives you the full record object once. The critical difference: getRefRecord() returns null for invalid references, while dot-walking returns empty strings that can mask data integrity issues.
When to use this
- When you need multiple fields from the same reference record in a single script
- When you need to validate the reference exists before proceeding with business logic
- When you need to call methods like
canRead()orisValidRecord()on the referenced record - When building complex conditions based on reference record properties in Business Rules or Script Includes
When NOT to use this
- Don't use for single field access —
current.assignment_group.nameis more efficient for one field - Don't use in client-side scripts — reference fields don't populate the same way on the client
- Don't use when looping over a GlideRecord that contains the reference data you need — query with
addJoinQuery()instead - Don't use for display values only —
getDisplayValue()on the reference field is lighter weight
Key behaviors and gotchas
- Returns
nullif the reference field is empty or points to a non-existent record — always null check - ACL restrictions apply to the returned GlideRecord — fields may be empty if the user lacks read access
- The returned GlideRecord is read-only by default — call
setWorkflow(false)beforeupdate()if modifying - Performance degrades in loops — if processing many records with the same reference, cache the
getRefRecord()result in a map - Domain separation applies — you may get
nullfor cross-domain references the current user cannot access - Works with reference fields only — will fail on string fields that contain sys_ids
Always combine getRefRecord() with isValidRecord() checks. A returned GlideRecord object doesn't guarantee the record exists or is accessible — invalid records return a GlideRecord that fails isValidRecord().
Enjoying this? Get one deep-dive per week.
Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.