Client scripts
Quick answer
Client scripts run in the user's browser on a form, letting you validate input, show or hide fields, and react the instant a value changes, without a round-trip to the server. They are the counterpart to server-side business rules: same language (JavaScript), opposite side of the wire.
Key takeaways
- The four types
- An onChange script
- Keep them light
- Try it Yourself
Client scripts run in the user's browser on a form, letting you validate input, show or hide fields, and react the instant a value changes, without a round-trip to the server. They are the counterpart to server-side business rules: same language (JavaScript), opposite side of the wire.
The four types
An onChange script
The g_form API is your toolbox: g_form.getValue(), setValue(), setMandatory(), setVisible(), setReadOnly(), addErrorMessage(). Use g_user to check roles on the client.
getReference or GlideRecord on the client, which freezes the form.Keep them light
- Prefer UI policies for simple show/hide/mandatory, no code, faster.
- Always guard
onChangewith theisLoadingcheck. - Move real logic to the server; the client should only shape the form.
Want to learn this properly?
Our live, instructor-led ServiceNow Training covers this hands-on, with real projects and a certification path.
Check your understanding
Client scripts run...
- A. In the browser
- B. On the database server
- C. On the MID Server
Show answer
A. In the browser
Client scripts execute in the user's browser.
Which type reacts to a single field changing?
- A. onChange
- B. onLoad
- C. onSubmit
Show answer
A. onChange
onChange fires when its configured field changes.
To fetch server data from a client script you should use...
- A. GlideAjax (async)
- B. Synchronous GlideRecord
- C. Nothing, it can't
Show answer
A. GlideAjax (async)
GlideAjax retrieves server data asynchronously without freezing the form.