Reference fields store sys_ids internally but display human-readable labels in the UI. New developers instinctively use getValue() expecting the display name, then wonder why they're getting 32-character strings instead. getDisplayValue() performs an additional query to fetch the display field from the referenced table — it's not just a formatting function. Understanding this distinction is critical because you'll need both methods depending on whether you're building user messages or database queries.
When to use getDisplayValue()
- Email notifications where you need user-friendly names instead of sys_ids
- Building display strings for UI messages or log entries
- Comparing reference field values to hardcoded display names in business logic
- Generating reports or exports where end users expect readable values
When NOT to use getDisplayValue()
- Building GlideRecord queries — use
getValue()to get the sys_id foraddQuery() - Setting reference field values —
setValue()expects sys_ids, not display values - Performance-critical loops — each
getDisplayValue()call triggers a database lookup - REST API payloads where client applications need stable sys_id references
Key behaviors and gotchas
getDisplayValue()returns an empty string for null references, whilegetValue()returns an empty string as well — checkfield.nil()for proper null detection- Display values respect ACLs — if the current user can't read the referenced record, you'll get an empty result
- The display field is determined by the referenced table's
displayattribute in the dictionary — usuallynameornumber - Works identically on extended tables — a reference to
cmdb_ci_serverwill return thenamefield from the basecmdb_citable - Cross-scope references may fail if the current scope lacks read access to the target application
Display values can change when referenced records are updated, making them unreliable for business logic comparisons. If you're checking if assigned_to equals 'John Smith', that logic breaks when John's display name changes to 'John A. Smith'. Use sys_ids for logic, display values for presentation.
Enjoying this? Get one deep-dive per week.
Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.