Skip to content
NowPath — Learn, Practice, Get Placed

Scripting · 6 min read read

ServiceNow Client Scripts Examples: onLoad, onChange, onSubmit

ServiceNow Client Scripts examples using g_form for onLoad, onChange and onSubmit, plus when to use UI Policies instead.

By the NowPath Institute trainer team ·

onLoad: show a message

Runs when the form loads.

function onLoad() {
  if (g_scratchpad.isVip) {
    g_form.addInfoMessage('VIP caller — handle with priority.');
  }
}

onChange: react to a field

Runs when a specific field value changes.

function onChange(control, oldValue, newValue, isLoading) {
  if (isLoading || newValue === '') return;
  g_form.setMandatory('close_notes', newValue == '6');
}

onSubmit: validate before save

Return false to stop the submission.

Client Script or UI Policy?

Use UI Policies for simple mandatory, read-only and visibility rules. Use Client Scripts when you need logic, server calls via GlideAjax or messages.

More scripting guides

START YOUR JOURNEY TODAY

Start your ServiceNow career this month.

Book a free demo class with a working ServiceNow Architect. New online and classroom batches in Hyderabad start every two weeks.

CallWhatsAppEmailVideo