CMDB relationships are stored asymmetrically in cmdb_rel_ci with explicit parent-child references, meaning you need two separate queries to get the complete relationship picture for any CI. Most developers make the mistake of only querying one direction, missing half the relationships. The real gotcha is that relationship ACLs can filter results differently for parent vs child queries, so a relationship visible in one direction might be hidden in the other.

When to use this

  • Building dependency maps or impact analysis for specific CIs
  • Populating related lists or relationship widgets in custom applications
  • Scheduled jobs that need to traverse CI relationships for reporting or cleanup
  • Business rules that trigger based on relationship changes and need full context

When NOT to use this

  • Don't use this in client scripts — use GlideAjax to call this Script Include instead
  • Don't use this for CIs with hundreds of relationships — use setLimit() and pagination instead
  • Don't use this when you only need specific relationship types — add addQuery('type', relationshipSysId) filters
  • Don't call this in a loop over multiple CIs — you'll create N+1 query problems. Use addQuery('parent', 'IN', ciSysIdArray) instead

Key behaviors and gotchas

  • Dot-walking to parent.name and child.name triggers additional database queries — cache results if processing many relationships
  • The type field references cmdb_rel_type records, not string values — use getDisplayValue() for human-readable names
  • CMDB ACLs can hide relationships even when both CIs are visible — relationship queries may return fewer results than expected
  • Domain separation affects cmdb_rel_ci queries — cross-domain relationships might not appear unless you have appropriate domain access
  • Deleted or inactive CIs remain in relationships until manually cleaned up — check parent.install_status and child.install_status if you need active relationships only
⚠️

The cmdb_rel_ci table is not indexed on parent+child combinations, only individual parent and child fields. Queries filtering on both parent AND child sys_ids will be slow on large CMDB instances.

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