What It Does

The addOrCondition method creates OR relationships between query conditions. Unlike addQuery which creates AND conditions, this method must be called on the GlideQueryCondition object returned by a previous addQuery or addOrCondition call.

Internally, ServiceNow builds a query tree where each addQuery creates a new branch connected by AND logic to the root query. When you call addOrCondition on a GlideQueryCondition, you're adding an OR branch to that specific condition, not to the root query. This creates parenthesized groupings in the resulting SQL WHERE clause.

The method returns a new GlideQueryCondition object representing the OR condition you just added. This return value can be chained to add additional OR conditions to the same group. The method never returns null or false - if the field name is invalid, ServiceNow will generate a runtime error when the query executes.

A critical edge case involves the relationship between OR conditions and encoded queries. If you mix addOrCondition with addEncodedQuery on the same GlideRecord, the encoded query becomes an additional AND condition at the root level, potentially negating your OR logic. The encoded query doesn't inherit the OR relationship structure you've built.

Unlike addQuery which can accept operator parameters, addOrCondition only accepts the two-parameter signature. To use operators like CONTAINS or STARTSWITH, you must embed them in the field name parameter (e.g., 'short_descriptionCONTAINS'). This method works with addNotNullQuery and addNullQuery in the same OR grouping.

When to Use This

Use addOrCondition when you need to create complex query logic where multiple conditions should match within the same logical group. This is essential for queries like "find incidents assigned to user A OR user B" or "show requests where category is hardware OR software". The method is also critical when building dynamic queries where the number of OR conditions isn't known at compile time.

When you need simple OR logic between different field types or when dealing with complex nested conditions, use addEncodedQuery instead. Encoded queries handle complex parenthesization better and are more readable for intricate logic. If you're building queries with more than 3-4 OR conditions, encoded queries become easier to maintain and debug.

⚠️

Never call addOrCondition directly on a GlideRecord object - it must be chained from a GlideQueryCondition returned by addQuery or another addOrCondition call.

Return Value

Returns a GlideQueryCondition object representing the newly added OR condition. This object contains the same methods as the original condition (addOrCondition, addCondition) and can be chained indefinitely. The return value is never null, even if you provide invalid field names - ServiceNow defers validation until query execution.

Store the returned GlideQueryCondition in a variable if you need to add more conditions to the same OR group later in your script. Each call to addOrCondition returns a new object representing the most recently added condition, not the root condition group.

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

Platform Behavior & Side Effects

  • No Business Rules, ACLs, or notifications fire during query construction - these only fire during record retrieval and modification operations
  • Nothing is written to the database until you call query(), next(), or a related execution method
  • Performance impact is minimal during query construction but OR conditions can create complex SQL that impacts execution performance
  • Query construction behavior is identical across all server-side contexts (Business Rules, Script Includes, Scheduled Jobs)
  • OR conditions are not cached by the platform and must be reconstructed in each script execution
  • Field access security (ACLs) still applies to OR conditions when the query executes, potentially filtering results
  • Debug logging captures the final SQL WHERE clause including OR groupings when query debugging is enabled