Skip to main content
Version: Latest (4.9.0)

Client-Side APIs

Reference for ServiceNow client-side APIs available in the browser. These APIs are shared across all Fluent APIs that execute client-side scripts — Client Scripts, UI Policy scripts (scriptTrue/scriptFalse), UI Actions (client-side), Catalog Client Scripts, and Catalog UI Policies.

Client-side scripts run in the browser and do not support JavaScript module imports (import/export). Use string scripts wrapped in the appropriate function signature (e.g., function onCondition() { } for UI Policies, function onLoad() { } for Client Scripts).

g_form (GlideForm)

The g_form object provides methods to interact with the current form — reading and setting field values, controlling visibility and mandatory state, and displaying messages.

Field Values

MethodDescription
getValue(field)Get the current value of a field
setValue(field, value)Set a field's value
clearValue(field)Clear a field's value

Field Display

MethodDescription
setVisible(field, bool)Show (true) or hide (false) a field
setDisplay(field, bool)Show/hide a field (alternative to setVisible)
setReadOnly(field, bool)Make a field read-only (true) or editable (false)
setMandatory(field, bool)Make a field required (true) or optional (false)

Choice Fields

MethodDescription
addOption(field, value, label)Add an option to a choice/dropdown field
clearOptions(field)Remove all options from a choice/dropdown field

Field Messages

MethodDescription
showFieldMsg(field, message, type)Display a message next to a field (type: 'error', 'info', 'warning')
hideFieldMsg(field)Remove the message next to a field

Form Messages

MethodDescription
addInfoMessage(message)Display an info banner at the top of the form
addErrorMessage(message)Display an error banner at the top of the form
addWarningMessage(message)Display a warning banner at the top of the form
clearMessages()Remove all banner messages from the form

Form State

MethodDescription
isNewRecord()Returns true if the form is for a new (unsaved) record
getUniqueValue()Get the sys_id of the current record
hasField(field)Check if a field exists on the form
submit()Programmatically submit the form
getFormElement()Get the underlying DOM form element
flash(field, color, count)Flash a field to draw user attention

References

MethodDescription
getReference(field, callback)Get the referenced GlideRecord for a reference field. Legacy — prefer GlideAjax for complex lookups

g_user (GlideUser)

The g_user object provides information about the currently logged-in user.

MethodDescription
hasRole(role)Check if the user has a specific role
getFullName()Get the user's full display name
getUserID()Get the user's sys_id
getName()Get the user's username

Additional Client APIs

APIDescription
g_scratchpadObject containing data passed from server-side Display Business Rules to the client. Use this to share server-computed values with client scripts without making additional AJAX calls
g_modalModal dialog controls (available in workspace context)
g_service_catalogService catalog form methods (available only in catalog item / record producer context)

Where client-side scripts appear in Fluent

Fluent APIScript propertyFunction signature
Client Script (onLoad)scriptfunction onLoad() { }
Client Script (onChange)scriptfunction onChange(control, oldValue, newValue, isLoading) { }
Client Script (onSubmit)scriptfunction onSubmit() { } — return false to cancel
Client Script (onCellEdit)scriptfunction onCellEdit(sysIDs, table, oldValues, newValue, callback) { }
UI PolicyscriptTrue / scriptFalsefunction onCondition() { }
UI Action (client-side)script + client.onClickCustom function name
Catalog Client ScriptscriptSame signatures as Client Script
Catalog UI PolicyscriptTrue / scriptFalsefunction onCondition() { }

Constraints

  • No module importsimport/export are not available in the browser. Use Now.include() to reference external .js files (see the now-include-guide topic)
  • No third-party libraries — only platform-provided APIs (g_form, g_user, GlideAjax, etc.) are available
  • Avoid synchronous server calls — use GlideAjax with async callbacks. getXMLWait() freezes the UI and is deprecated in scoped apps
  • Guard onChange against initial load — always check if (isLoading) return; at the start of onChange scripts to prevent execution during form load