What It Does

The addActiveQuery() method adds a query condition that filters results to only include records where the 'active' field equals true. When ServiceNow executes the query, it translates this into a SQL WHERE clause that checks active = 1 in the database.

Internally, ServiceNow treats this method identically to calling addQuery('active', true). The method exists purely as syntactic sugar to make code more readable and express intent more clearly. When you build the query, ServiceNow adds this condition to its internal query builder along with any other conditions you've specified.

The method returns void — it modifies the GlideRecord object's query conditions but doesn't return anything. The filtering only takes effect when you call query() to execute the query. If no records match your conditions (including the active filter), the subsequent next() calls will return false.

⚠️

If you call addActiveQuery() on a table that doesn't have an 'active' field, ServiceNow will throw a runtime error when you execute the query.

The method works identically to other GlideRecord query methods like addQuery() and addNullQuery() — you can chain multiple conditions together, and they combine with AND logic. You can call addActiveQuery() before or after other query conditions without affecting the final result.

When to Use This

Use addActiveQuery() when you need to query tables where the 'active' field represents whether records should be considered current or valid. Most ServiceNow configuration tables (users, groups, locations, categories) use the active field to indicate whether the record is currently in use. This method makes your code's intent explicit — you're specifically looking for active records, not accidentally including inactive ones.

Don't use this method when you need inactive records or when you need both active and inactive records. In those cases, either skip the active filter entirely or use addQuery('active', false) for inactive records specifically. Also avoid using this on tables that don't have an active field — check the table schema first, especially when working with custom tables or tables you're unfamiliar with.

Return Value

The method returns void — it doesn't return any value. The method modifies the GlideRecord object's internal query state and returns control to your script. You cannot chain method calls off addActiveQuery() because there's nothing to chain from.

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 database queries execute when you call this method — it only modifies the query builder
  • Business Rules, ACLs, and other query-time mechanisms don't fire until you call query()
  • Performs identically to addQuery('active', true) with no performance difference
  • Will cause a runtime error if called on tables without an 'active' field when the query executes
  • Works in all server-side contexts (Business Rules, Script Includes, Scheduled Jobs, UI Actions)
  • Does not trigger audit entries or field-level security checks until query execution
  • Can be called multiple times on the same GlideRecord without error (though redundant)