The addOrCondition() method creates OR brackets that apply only to the last addQuery() call, not the entire query. This is the critical mental model developers miss: OR conditions don't float freely — they're chained to a specific query condition and create a bracketed group. Without understanding this scoping behavior, you'll build queries that return completely different result sets than expected, especially when mixing AND and OR logic in complex filters.

When to use this

  • When you need to match multiple specific values for the same field (priority 1 OR priority 2)
  • When you need OR logic between different fields within an AND-based query structure
  • In Business Rules where you need to process records matching flexible criteria but with bounded result sets
  • When building dynamic queries where OR conditions are determined at runtime

When NOT to use this

  • Don't use this for simple IN operations — use addQuery('field', 'IN', 'value1,value2') instead
  • Don't use this in client scripts — the query won't execute server-side where OR conditions are processed
  • Don't use this when you only need record counts — use GlideAggregate with addHaving() for OR logic
  • Don't use this for complex nested OR/AND logic — use encoded queries with addEncodedQuery() instead

Key behaviors and gotchas

  • OR conditions must be chained directly from addQuery() — calling addOrCondition() on a separate line breaks the chain
  • State field values use integers (1, 2, 3, etc.) not display values — 'Open' will return zero results
  • Domain separation applies to each OR condition independently — results may vary by domain
  • Performance degrades significantly when OR conditions span non-indexed fields
  • ACL evaluation happens per OR condition — users may see partial result sets if they lack read access to specific field values
  • Multiple addOrCondition() calls create a single OR bracket — you cannot create nested OR groups
⚠️

OR conditions only apply to the last addQuery() call. If you call addQuery() after addOrCondition(), the OR bracket closes and subsequent conditions are AND-ed to the main query. This scoping behavior catches developers who expect OR conditions to float freely across the entire query.

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