Client vs server scripting
Quick answer
Most of ServiceNow is configured, not coded, but when configuration runs out, you script. The first and most important thing to master is where code runs, because client-side and server-side scripting have completely different APIs, powers and pitfalls. Get the location model right and everything else follows.
Key takeaways
- Client vs server, the fundamental divide
- Client-side script types
- The g_form API (client)
- Prefer no-code first
- Common mistakes
Most of ServiceNow is configured, not coded, but when configuration runs out, you script. The first and most important thing to master is where code runs, because client-side and server-side scripting have completely different APIs, powers and pitfalls. Get the location model right and everything else follows.
Client vs server, the fundamental divide
g_form, g_user, g_scratchpad. Types: Client Scripts, UI Policies.current, previous, gs. Types: Business Rules, Script Includes, jobs.Client-side script types
The g_form API (client)
GlideRecord or getReference call freezes the browser while it waits on the server. Use an async GlideAjax call to a Script Include instead, or move the logic server-side.Prefer no-code first
Before writing a client script, ask whether a UI policy does it (mandatory/read-only/visible by condition), it's declarative, faster, and survives upgrades better. Reserve client scripts for logic policies can't express.
Common mistakes
- Putting heavy logic client-side and freezing the form.
- Using
g_formon the server orGlideRecordon the client. - Synchronous
GlideAjax/getReferenceinstead of the async callback form. - Scripting what a UI policy or flow could do no-code.
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
onChange and onLoad scripts run...
- A. Client-side in the browser
- B. On the database
- C. Nowhere
Show answer
A. Client-side in the browser
They react to form events in the browser.
GlideRecord is used mainly on the...
- A. Server side
- B. Client side
- C. Printer
Show answer
A. Server side
Server-side scripts use GlideRecord.
To get server data from client code you use...
- A. GlideAjax
- B. CSS
- C. A report
Show answer
A. GlideAjax
GlideAjax calls a client-callable Script Include.