The IN operator in ServiceNow queries expects a comma-separated string, not an array. Most developers stumble when converting arrays of sys_ids into this format—they miss that empty strings or null values in the list will cause the query to behave unexpectedly, often returning no results when it should. The platform doesn't automatically filter these out, so you must sanitize your input array before joining it.
When to use this
- Batch lookups after collecting
sys_idsfrom another query or user input - Filtering by specific state values when you need multiple states like active incident statuses
- Processing records where a choice field matches several predetermined values
- Script Includes or Business Rules where you control the input data and list size
When NOT to use this
- Don't use with uncontrolled list sizes—
INqueries with hundreds of values perform poorly. UsesetLimit()and batch processing instead - Don't use in client scripts—the query runs server-side anyway. Use
GlideAjaxto call a Script Include instead - Don't use when you only need counts or aggregates—use
GlideAggregatewithINinstead of fetching full records - Don't nest this inside loops over other
GlideRecordqueries—you'll create N+1 query problems
Key behaviors and gotchas
- Empty strings or null values in your comma-separated list will cause the entire
INcondition to malfunction—always filter them out first - State values must be integers (1,2,3) not strings ('New','In Progress')—the database stores choice values as numbers
- Reference fields like
assignment_groupexpectsys_ids, not display values - ACLs still apply—records will be silently filtered from results based on the current user's permissions
- Performance degrades significantly with more than 50-100 values in the
INlist, especially on non-indexed fields - Domain separation applies—cross-domain records won't appear unless you're in the global domain or have proper visibility
Never call .join(',') on an array without filtering out empty values first. A single empty string in your array will break the entire IN condition, and ServiceNow won't tell you why your query returned nothing.
Enjoying this? Get one deep-dive per week.
Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.