What It Does
The setDisplayValue method allows you to set a field's value using its human-readable display representation rather than the internal database value. This is particularly powerful for reference fields, where you might know the name of a user or configuration item but not their sys_id.
When you call setDisplayValue, ServiceNow doesn't immediately resolve the display value. Instead, it stores the display value temporarily and performs the resolution when you call insert() or update(). The platform searches the referenced table's display field for an exact match and uses the corresponding sys_id.
The method returns void and provides no immediate feedback about whether the display value will successfully resolve. If ServiceNow cannot find a matching record when you save, the field will be set to empty/null rather than throwing an error. This silent failure behavior requires defensive coding practices.
For non-reference fields, setDisplayValue often behaves identically to setValue, but there are exceptions. Choice fields will accept display labels, and date/time fields can accept formatted strings. The key difference from setValue is that this method always treats the input as user-facing data rather than raw database values.
Unlike getDisplayValue which reads display values, or getValue which reads raw values, this method specifically handles the complexity of translating human-readable input into database-appropriate values. It's the programmatic equivalent of what happens when a user types into a reference field in the ServiceNow UI.
When to Use This
Use setDisplayValue when you're working with data imports, integrations, or user inputs where you have display names but not sys_ids. This commonly occurs when processing CSV files, web service calls, or forms where users select items by name. It's also essential when creating records based on external system data that uses readable identifiers rather than ServiceNow's internal IDs.
Avoid this method when you already have the sys_id – use setValue instead for better performance and reliability. Don't use setDisplayValue in tight loops or when processing large datasets, as the display value resolution adds overhead. Also avoid it when the display values might not be unique, as ServiceNow will pick the first match it finds, which may not be the intended record.
Never rely on setDisplayValue for critical data integrity. Always verify the field was set correctly after saving, as resolution failures are silent.
Return Value
This method returns void – it provides no return value and no immediate indication of success or failure. The display value is stored internally and will be resolved during the next database operation. This means you cannot determine if the display value is valid until after calling insert() or update().
Since there's no return value to check, you should verify successful field population by reading the field value after saving the record. Use getValue() to check if the field contains a sys_id, or getDisplayValue() to confirm the display value was resolved correctly.
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
- Display value resolution occurs during database save operations, not when the method is called, adding latency to insert/update operations
- Business Rules, ACLs, and other server-side logic see the resolved sys_id value, not the original display value you passed in
- Failed display value resolution results in empty/null field values with no error thrown, potentially causing silent data quality issues
- Resolution queries against referenced tables respect ACLs, so users' read permissions affect which display values can be successfully resolved
- Multiple records with identical display values will resolve to the first match found, making the behavior non-deterministic in some cases
- Performance impact increases with table size since resolution requires querying the referenced table's display field
- Audit records capture the final sys_id value after resolution, not the original display value that was set