/servicenow:gliderecord-patternsfrom ServiceNow
Provides best practices for ServiceNow GlideRecord queries: addQuery vs addEncodedQuery, setLimit, GlideAggregate for counts, avoiding N+1 in loops, and safe CRUD with workflow control.
Ships in ServiceNow. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
GlideRecord is the primary API for database operations in ServiceNow. Following these patterns ensures efficient and secure queries.
var gr = new GlideRecord("incident")
if (gr.get("sys_id_here")) {
gs.info("Found: " + gr.getValue("number"))
}
var gr = new GlideRecord("sys_user")
if (gr.get("user_name", "admin")) {
gs.info("Found user: " + gr.getValue("name"))
}
var gr = new GlideRecord("incident")
gr.addQuery("active", true)
gr.addQuery("priority", "1")
gr.orderByDesc("sys_created_on")
gr.setLimit(100)
gr.query()
while (gr.next()) {
gs.info(gr.getValue("number"))
}
Use encoded queries for complex conditions - they're more efficient than multiple addQuery calls:
var gr = new GlideRecord("incident")
// Encoded query from list view URL or Query Builder
gr.addEncodedQuery("active=true^priority=1^assigned_toISEMPTY")
gr.query()
while (gr.next()) {
// Process records
}
// When you only need X records
var gr = new GlideRecord("incident")
gr.addQuery("active", true)
gr.setLimit(10) // Don't fetch more than needed
gr.query()
// CORRECT - Returns string value
var number = gr.getValue("number")
// ALSO WORKS but returns GlideElement
var element = gr.number
var numberStr = gr.number.toString()
// Get the display value of a reference field
var assignedToName = gr.getDisplayValue("assigned_to")
// Get the sys_id of a reference field
var assignedToId = gr.getValue("assigned_to")
// BAD - Query inside loop
for (var i = 0; i < userIds.length; i++) {
var gr = new GlideRecord("sys_user")
gr.get(userIds[i]) // N queries!
}
// GOOD - Single query with IN clause
var gr = new GlideRecord("sys_user")
gr.addQuery("sys_id", "IN", userIds.join(","))
gr.query()
while (gr.next()) {
// Process all users at once
}
// BAD - Counting with GlideRecord
var count = 0
var gr = new GlideRecord("incident")
gr.addQuery("active", true)
gr.query()
while (gr.next()) {
count++
}
// GOOD - Use GlideAggregate
var ga = new GlideAggregate("incident")
ga.addQuery("active", true)
ga.addAggregate("COUNT")
ga.query()
if (ga.next()) {
var count = ga.getAggregate("COUNT")
}
var gr = new GlideRecord("incident")
gr.initialize()
gr.setValue("short_description", "New incident")
gr.setValue("caller_id", gs.getUserID())
gr.setValue("priority", "3")
var sysId = gr.insert()
var gr = new GlideRecord("incident")
if (gr.get("sys_id_here")) {
gr.setValue("state", "6") // Resolved
gr.setValue("close_notes", "Issue fixed")
gr.update()
}
var gr = new GlideRecord("incident")
if (gr.get("sys_id_here")) {
gr.deleteRecord()
}
var gr = new GlideRecord("incident")
gr.addQuery("state", "6") // Resolved
gr.addQuery("resolved_at", "<", gs.daysAgoStart(30))
gr.query()
while (gr.next()) {
gr.setValue("state", "7") // Closed
gr.update()
}
| Operator | Example | Description |
|---|---|---|
= | addQuery('active', true) | Equals |
!= | addQuery('active', '!=', true) | Not equals |
>, < | addQuery('priority', '<', '3') | Greater/Less than |
>=, <= | addQuery('sys_created_on', '>=', gs.daysAgoStart(7)) | Greater/Less or equal |
CONTAINS | addQuery('short_description', 'CONTAINS', 'error') | Contains string |
STARTSWITH | addQuery('number', 'STARTSWITH', 'INC') | Starts with |
ENDSWITH | addQuery('email', 'ENDSWITH', '@company.com') | Ends with |
IN | addQuery('state', 'IN', '1,2,3') | In list |
NOT IN | addQuery('state', 'NOT IN', '6,7') | Not in list |
ISEMPTY | addQuery('assigned_to', 'ISEMPTY', '') | Field is empty |
ISNOTEMPTY | addQuery('assigned_to', 'ISNOTEMPTY', '') | Field is not empty |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
gliderecord, servicenow, query-optimization, n-plus-one, crud-patterns
npx claudepluginhub serac-labs/serac --plugin servicenow70 skills in this plugin
/acl-securityCreate and debug ServiceNow ACLs (record, field, REST, script-include). Covers role/condition/script patterns, which ACL names can apply to a table or field, field-level visibility, and impersonation testing for row- and field-level security./agent-workspaceBuild ServiceNow Agent Workspace configurations — workspaces, lists, forms, contextual side panels, Agent Assist similar-record finders, and workspace-specific UI actions on sys_aw_* tables./agile-developmentServiceNow Agile Development 2.0 — the rm_team → rm_sprint → rm_story → rm_epic model, the state and point values ServiceNow actually accepts, how a story is attached to a sprint, and the reporting tools (board, burndown, velocity, capacity, standup, retrospective).Other plugins' skills for the same job