Script includes
Reusable server-side code you can call anywhere.
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
- 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.
▸ Press Run to execute.
Runs in a sandbox in your browser. Mock gs and GlideRecord and sample data are provided.