The critical insight here is that assignment groups are referenced by sys_id, not display name. Most developers instinctively try to query by group name first, which fails in enterprise instances where group names aren't unique across domains. Always use the sys_id from the sys_user_group table, and the platform handles domain separation automatically. The assignment_group field is indexed and reference-qualified, making this pattern performant even on millions of records.
When to use this pattern
- Business Rules that need to process all incidents for a specific team during record updates
- Scheduled Jobs that generate group-specific reports or notifications
- Script Includes that implement group-based workflow logic where you need field values from multiple columns
- Fix Scripts for data cleanup operations scoped to specific assignment groups
When NOT to use this pattern
- Client Scripts β use GlideAjax to call a Script Include that runs this server-side
- When you only need counts or aggregations β use GlideAggregate instead
- Inside loops over other GlideRecord queries β you'll create N+1 performance problems
- For real-time UI components β use REST Table API or GraphQL instead
Key behaviors and gotchas
- State values are integers:
'1'(New),'2'(In Progress),'6'(Resolved),'7'(Closed) β never use display values - The
assignment_groupfield is indexed and performs well, but combining with non-indexed fields kills performance - ACLs apply to the query results β users will only see incidents they have read access to
- Use
hasNext()before looping β empty result sets are common andnext()on empty sets returnsfalse - Domain separation automatically filters results to the user's domain when the assignment group has domain restrictions
- Always order results with
orderBy()β database order is unpredictable without explicit sorting
Never concatenate user input directly into group sys_id queries. If the group identifier comes from user input, validate it exists in sys_user_group first to prevent injection attacks and confusing empty result sets.
Enjoying this? Get one deep-dive per week.
Join 1,000+ ServiceNow pros β scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.