Script includes
Quick answer
Script Includes are reusable server-side code, the place to keep logic you call from multiple business rules, flows, or client scripts (via GlideAjax). They are ServiceNow's answer to "don't repeat yourself", and the correct home for anything non-trivial.
Key takeaways
- The class pattern
- Calling from the client: GlideAjax
- On-demand functions and scopes
- Common mistakes
- Try it Yourself
Script Includes are reusable server-side code, the place to keep logic you call from multiple business rules, flows, or client scripts (via GlideAjax). They are ServiceNow's answer to "don't repeat yourself", and the correct home for anything non-trivial.
The class pattern
Call it anywhere server-side: new IncidentUtils().isVip(gs.getUserID()). The type property must match the name or instantiation breaks.
Calling from the client: GlideAjax
Client scripts can't touch the database directly, they call a Script Include that extends AbstractAjaxProcessor via GlideAjax. This is the correct, non-blocking way to fetch server data on a form:
On-demand functions and scopes
Common mistakes
- Copy-pasting the same logic into many business rules instead of an include.
- Making includes client-callable unnecessarily.
- Forgetting the
typeproperty, breaking instantiation. - Using the synchronous
getXMLWait()form and freezing the browser.
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
A script include is...
- A. Reusable server-side code
- B. A stylesheet
- C. A report
Show answer
A. Reusable server-side code
It centralises logic for reuse.
To call one from client code, tick...
- A. Client callable
- B. Read only
- C. Active only
Show answer
A. Client callable
Client callable exposes it to GlideAjax.
Script includes help you avoid...
- A. Copying logic everywhere
- B. Using tables
- C. Logging in
Show answer
A. Copying logic everywhere
They keep one authoritative copy of the code.