ServiceNow Legacy Scripting
ServiceNow legacy scripting uses the GlideRecord API for server-side data access, Script Include classes for reusable server-side logic, Business Rules for server-side automation, and g_form/g_user/g_list for client-side form manipulation. All APIs are described in the reference files below.
References
Read these files when you need them — do not pre-load all references at session start. Paths are relative to the skill root (the directory containing this SKILL.md file).
| File |
When to Read |
references/gliderecord.md |
Generating or reviewing GlideRecord queries, CRUD operations, or addQuery/getValue patterns |
references/server-side.md |
Generating Script Includes, Business Rules, or using GlideSystem (gs.*) logging |
references/client-side.md |
Generating Client Scripts using g_form, g_user, or g_list; or any client-side form manipulation |
references/gotchas.md |
Before generating or reviewing any ServiceNow script — check for hallucination traps |
Scripts
| Script |
When to use |
scripts/validate-script.sh |
When validating a ServiceNow script file for common issues before deploying |
Examples
Use these as structural templates — only read the example that matches your target type, do not pre-load all examples:
| File |
Demonstrates |
assets/examples/gliderecord-crud.js |
Complete GlideRecord CREATE, READ (single and multi), UPDATE, DELETE with correct getValue() usage |
assets/examples/script-include-class.js |
Script Include using Class.create() pattern with initialize(), utility methods, and type property |
assets/examples/client-script-gform.js |
Client Script onLoad/onChange handlers using g_form.getValue(), g_form.setMandatory(), g_user.hasRole() |
Hard Rules
Never use GlideRecord when ServiceNow Fluent SDK is present.
If the workspace contains now.config.json, .now.ts files, or imports from @servicenow/sdk/core,
the developer is working in a Fluent SDK application. Stop and redirect:
"I can see you're working in a Fluent SDK project. Use the sn-sdk-fluent skill to generate
typed metadata definitions instead of GlideRecord scripts. GlideRecord is the legacy scripting
API and does not work inside Fluent SDK .now.ts files."
GlideRecord is server-side only — never generate GlideRecord in a Client Script. Use GlideAjax.
Always call query() before next() — while(gr.next()) without gr.query() never executes.
Use getValue() in loops — gr.field_name returns a pointer; gr.getValue('field_name') returns the string value.
Only use documented API methods — do not invent methods like gr.getField(), gr.setQuery(), or gr.addOrder().
Behavior by Task Type
Generating
- Check for Fluent SDK signals first (Hard Rule 1) — if detected, redirect immediately; do not generate GlideRecord code.
- Identify the script context: server-side (Business Rule, Script Include) or client-side (Client Script).
- For server-side: read
references/gliderecord.md for CRUD patterns, references/server-side.md for Script Include structure and Business Rule context variables.
- For client-side: read
references/client-side.md for g_form/g_user/g_list APIs. Never generate GlideRecord in a client script (Hard Rule 2).
- Use example files in
assets/examples/ as working templates.
Reviewing
- Check Hard Rules 3 and 4: query() before next(), getValue() in loops.
- Verify no GlideRecord in client-side code (Hard Rule 2).
- Verify no invented methods — compare against
references/gliderecord.md documented API (Hard Rule 5).
- Run
scripts/validate-script.sh <file> to check for GlideRecord in client scripts, bare setAbortAction, and g_form misuse.
Explaining
- Route the developer to the relevant reference file for detailed method documentation.
- For Fluent SDK questions, redirect to the sn-sdk-fluent skill.
1---2name: sn-scripting3description: Generates GlideRecord queries, Script Include classes, and client scripts for ServiceNow legacy scripting. Use for Business Rules, Scheduled Jobs, server-side Script Includes, and client-side g_form/g_user scripts. Redirects to sn-sdk-fluent when Fluent SDK is detected in the workspace.4license: Apache-2.05---67# ServiceNow Legacy Scripting89ServiceNow legacy scripting uses the GlideRecord API for server-side data access, Script Include classes for reusable server-side logic, Business Rules for server-side automation, and g_form/g_user/g_list for client-side form manipulation. All APIs are described in the reference files below.1011## References1213Read these files when you need them — do not pre-load all references at session start. Paths are relative to the skill root (the directory containing this `SKILL.md` file).1415| File | When to Read |16|------|-------------|17| `references/gliderecord.md` | Generating or reviewing GlideRecord queries, CRUD operations, or addQuery/getValue patterns |18| `references/server-side.md` | Generating Script Includes, Business Rules, or using GlideSystem (gs.*) logging |19| `references/client-side.md` | Generating Client Scripts using g_form, g_user, or g_list; or any client-side form manipulation |20| `references/gotchas.md` | Before generating or reviewing any ServiceNow script — check for hallucination traps |2122## Scripts2324| Script | When to use |25|--------|------------|26| `scripts/validate-script.sh` | When validating a ServiceNow script file for common issues before deploying |2728## Examples2930Use these as structural templates — only read the example that matches your target type, do not pre-load all examples:3132| File | Demonstrates |33|------|-------------|34| `assets/examples/gliderecord-crud.js` | Complete GlideRecord CREATE, READ (single and multi), UPDATE, DELETE with correct getValue() usage |35| `assets/examples/script-include-class.js` | Script Include using Class.create() pattern with initialize(), utility methods, and type property |36| `assets/examples/client-script-gform.js` | Client Script onLoad/onChange handlers using g_form.getValue(), g_form.setMandatory(), g_user.hasRole() |3738## Hard Rules39401. **Never use GlideRecord when ServiceNow Fluent SDK is present.**41 If the workspace contains `now.config.json`, `.now.ts` files, or imports from `@servicenow/sdk/core`,42 the developer is working in a Fluent SDK application. Stop and redirect:43 "I can see you're working in a Fluent SDK project. Use the sn-sdk-fluent skill to generate44 typed metadata definitions instead of GlideRecord scripts. GlideRecord is the legacy scripting45 API and does not work inside Fluent SDK `.now.ts` files."46472. **GlideRecord is server-side only** — never generate GlideRecord in a Client Script. Use GlideAjax.48493. **Always call query() before next()** — while(gr.next()) without gr.query() never executes.50514. **Use getValue() in loops** — gr.field_name returns a pointer; gr.getValue('field_name') returns the string value.52535. **Only use documented API methods** — do not invent methods like gr.getField(), gr.setQuery(), or gr.addOrder().5455## Behavior by Task Type5657### Generating58591. Check for Fluent SDK signals first (Hard Rule 1) — if detected, redirect immediately; do not generate GlideRecord code.602. Identify the script context: server-side (Business Rule, Script Include) or client-side (Client Script).613. For server-side: read `references/gliderecord.md` for CRUD patterns, `references/server-side.md` for Script Include structure and Business Rule context variables.624. For client-side: read `references/client-side.md` for g_form/g_user/g_list APIs. Never generate GlideRecord in a client script (Hard Rule 2).635. Use example files in `assets/examples/` as working templates.6465### Reviewing66671. Check Hard Rules 3 and 4: query() before next(), getValue() in loops.682. Verify no GlideRecord in client-side code (Hard Rule 2).693. Verify no invented methods — compare against `references/gliderecord.md` documented API (Hard Rule 5).704. Run `scripts/validate-script.sh <file>` to check for GlideRecord in client scripts, bare setAbortAction, and g_form misuse.7172### Explaining73741. Route the developer to the relevant reference file for detailed method documentation.752. For Fluent SDK questions, redirect to the sn-sdk-fluent skill.