The state field is an integer choice field where ServiceNow stores numeric values (1, 2, 3, 6, 7) but displays text labels (New, In Progress, etc.). Most developers instinctively query with addQuery('state', 'In Progress') and wonder why they get zero results. The platform doesn't translate display values to database values in queries — you must use the integer. This pattern handles the common case of processing incidents by workflow state while avoiding the query-in-a-loop antipattern that kills performance.

When to use this

  • When you need to process incidents in a specific workflow state from server-side scripts
  • When building scheduled jobs that act on incidents based on their current state
  • When you need to read and potentially update multiple fields per incident record
  • When the result set is bounded by other filters (assignment group, priority, date range)

When NOT to use this

  • Don't query incidents from client scripts — use GlideAjax to call a Script Include instead
  • Don't use this when you only need counts or aggregates — use GlideAggregate for better performance
  • Don't embed this query inside loops over other GlideRecord results — you'll create N+1 query problems
  • Don't use this for real-time state transitions in Business Rules — check current.state and previous.state instead

Key behaviors and gotchas

  • State values are integers: 1=New, 2=In Progress, 3=On Hold, 6=Resolved, 7=Closed. Never query with display labels
  • The state field is indexed, making single-state queries fast even on large incident tables
  • Always add setLimit() to prevent runaway queries — production incident tables can have 100k+ records
  • Domain separation applies — you'll only see incidents in your current domain scope
  • ACL restrictions apply even in Business Rules — queries respect user context and field-level security
  • Custom state values beyond the default 7 will use higher integers (8, 9, 10...) in order of creation
⚠️

Never call update() inside a Business Rule on the same record that triggered the rule — you'll create infinite recursion. Use current.setValue() instead for the triggering record.

Free Newsletter

Enjoying this? Get one deep-dive per week.

Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.

No spam · Unsubscribe anytime