The fundamental distinction between getValue() and getDisplayValue() trips up every developer initially. getValue() returns the actual database value β integers for choice fields, sys_ids for references, raw strings for text fields. getDisplayValue() returns what the user sees β choice labels, reference display values, formatted text. The classic mistake is using getDisplayValue() in conditional logic, then wondering why your string comparisons fail when the platform expects integer or sys_id comparisons.
When to use this
- When you need to read current field values in onChange, onLoad, or onSubmit Client Scripts
- When building conditional logic based on choice field states or reference field assignments
- When you need to display user-friendly messages using field labels instead of raw values
- When validating form data before submission in client-side UI Actions
When NOT to use this
- Don't use in Business Rules or other server-side scripts β use
current.field_nameinstead - Don't use to read values from other forms or records β use GlideAjax to call server-side lookups
- Don't use
getDisplayValue()in conditional comparisons β choice labels can change, breaking your logic - Don't assume fields have values β always check for null, empty string, or undefined
Key behaviors and gotchas
- Choice fields return string representations of integers:
'1'not1β use string comparison or loose equality - Reference fields:
getValue()returns the 32-character sys_id,getDisplayValue()returns the display field value - Empty reference fields return empty string
'', not null β check for both!fieldandfield !== '' - Both methods return
nullfor fields that don't exist on the form β check field existence first in dynamic forms - Journal fields and encrypted fields cannot be read via
getValue()for security reasons - Date/time fields return the internal format, not the user's display format β use
getDisplayValue()for user messages
Never use getDisplayValue() in conditional logic or for field comparisons. Choice labels and reference display values can be changed by administrators, breaking your conditions. Always use getValue() for logic, getDisplayValue() only for user-facing text.
Enjoying this? Get one deep-dive per week.
Join 1,000+ ServiceNow pros β scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.