Get the display value in a client script
Short answer
g_form.getValue('assigned_to') returns the sys_id. To read the label the user actually sees, use g_form.getDisplayValue('assigned_to') — or on older releases g_form.getDisplayBox('assigned_to').value. For choice and reference fields those two calls return different strings, so never compare a display value against a sys_id.
Where: System Definition → Client Scripts → New (type: onChange / onLoad), or the Catalog Client Scripts table for catalog items
Steps
1.Decide which value you actually need
getValue() gives the stored value: a sys_id for reference fields, the choice value for choice fields. getDisplayValue() gives the human label. Validation and queries want the stored value; messages, confirmations and field defaults usually want the display value.
var userId = g_form.getValue('assigned_to'); // 62826bf03710... var userName = g_form.getDisplayValue('assigned_to'); // "Beth Anglin"2.Read the display value in an onChange script
Guard the top of every onChange script with the standard isLoading / newValue check, then read the display value from the field that changed.
function onChange(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue === '') return; var label = g_form.getDisplayValue('assigned_to'); g_form.addInfoMessage('Assigned to ' + label); }3.Fall back to getDisplayBox for older instances
getDisplayValue() is not available on every release or every field widget. getDisplayBox() returns the input element that holds the label, so read its .value — and null-check it, because read-only or hidden reference fields have no display box.
function displayLabel(field) { if (g_form.getDisplayValue) return g_form.getDisplayValue(field); var box = g_form.getDisplayBox(field); return box ? box.value : g_form.getValue(field); }4.Read choice field labels the same way
For a choice field getValue('priority') returns '1' while getDisplayValue('priority') returns '1 - Critical'. Compare against the value, display the label.
if (g_form.getValue('priority') === '1') { g_form.addInfoMessage('Priority set to ' + g_form.getDisplayValue('priority')); }5.Set a display value without triggering more scripts
g_form.setValue(field, sysId, displayValue) sets both halves of a reference field in one call, which stops the platform from doing an extra round trip to resolve the label. Pass the third argument whenever you already know it.
g_form.setValue('assigned_to', userId, userName);6.Test in both the classic form and Next Experience
Open the record in the classic UI and in a workspace form, change the field, and confirm the message. Workspace forms ignore DOM access, so a script that reached into the display box element instead of using the g_form API will silently fail there.
Common mistakes
- Comparing getDisplayValue() output to a sys_id — the strings never match, so the branch never fires.
- Using document.getElementById('sys_display.incident.assigned_to') — DOM access is unsupported and breaks in Next Experience and Service Portal.
- Forgetting the isLoading guard, which makes the script run once on form load with the stored value.
- Calling getDisplayBox() on a read-only or hidden field and dereferencing null.
- Calling setValue() with only the sys_id in a loop — each call forces a server lookup for the label.
FAQ
What is the difference between g_form.getValue and g_form.getDisplayValue?
getValue returns the stored database value — a sys_id for reference fields, the choice value for choice fields. getDisplayValue returns the label the user sees, such as the user's name or '1 - Critical'.
Why does g_form.getDisplayBox return null?
The field has no visible display input: it is hidden, read-only, or rendered by a widget that does not create a display box. Guard the call and fall back to getDisplayValue or getValue.
Can I get the display value of a field that is not on the form?
No. g_form only sees fields on the current form. Use GlideAjax to a client-callable Script Include, or add the field to the form as hidden.