4.1 CMDB Query Builder
Key Takeaways
- CMDB Query Builder permits constructing visual queries that join CMDB CI classes, relationship types, and standard non-CMDB platform tables such as Assets or Incidents.
- Saved queries from the CMDB Query Builder are stored in the qb_saved_query table and can be shared, scheduled, or dynamically linked to CMDB Groups.
- The canvas enforces constraint validation, allowing authors to define relationship direction, specific relationship classes, and cardinality (e.g. 1-to-many).
- Dynamic CI Groups leverage saved CMDB Query Builder queries to automatically manage group membership, directly supporting CSDM Technical Service Offerings.
In complex IT environments, reporting on single configuration items (CIs) is insufficient. Implementers must understand how CIs are interconnected across class hierarchies. The ServiceNow CMDB Query Builder provides a visual, drag-and-drop canvas to build, run, and save queries across multiple CI classes, relationship types, and even standard non-CMDB tables (such as Incidents, Assets, or Users). This tool abstracts complex SQL joins and database views into a graphical representation, making it a critical component of CMDB governance and service design.
Core Capabilities and Visual Canvas
The Query Builder operates on a unified canvas where users can build queries by dragging components from a palette. The palette contains:
- CMDB CI Classes: Any class in the CMDB class hierarchy (e.g., Linux Server, Tomcat Web Server, Application Service).
- Non-CMDB Tables: Standard tables in the ServiceNow platform that refer to CIs, such as Asset [alm_asset], Incident [incident], Change Request [change_request], or User [sys_user].
- Saved Queries: Existing queries that can be nested or reused.
Nodes and Connections
Queries are built using Nodes and Connections:
- Nodes: Represent the CI classes or non-CMDB tables you want to query. When a node is placed on the canvas, it represents a set of records. Users can apply filters to nodes (e.g., filtering a Windows Server node where the operating system version is Server 2022).
- Connections: Dragging a connection line between two nodes defines a relationship. ServiceNow allows you to specify whether the relationship is:
- CMDB Relationship: Traces direct relationships stored in the
cmdb_rel_citable. You can specify a parent-child direction (e.g., Application Runs on Server) or keep it generic. - Non-CMDB Join: Joins a CMDB class node with a non-CMDB table node based on reference fields. For example, joining a Server node to an Incident node where the Incident's "Configuration item" field references the Server.
- CMDB Relationship: Traces direct relationships stored in the
Relationship Constraints and Filters
When configuring relationship connections, query authors can define specific constraints to narrow search results:
- Relationship Type: You can restrict the connection to specific relationship classes, such as Runs on, Depends on, or Uses. If left blank, the query matches any active relationship.
- Cardinality: You can configure relationship cardinality constraints, such as one-to-one, one-to-many, or many-to-many, to isolate specific topologies.
- Filters: Just as filters can be applied to nodes, they can also be applied to relationships. For instance, filtering on attributes of the relationship record itself, such as the port number or status of a connection.
CMDB Query Builder vs. Standard Reporting
Traditional ServiceNow reporting relies on single tables or predefined Database Views (sys_db_view). Database views require administrative privileges to create and require writing SQL-like join conditions. CMDB Query Builder bypasses these limitations for CMDB-related querying.
| Feature | CMDB Query Builder | Standard Reporting / Database Views |
|---|---|---|
| Interface | Visual drag-and-drop canvas | Form-based configuration |
| Relationship Traversal | Dynamic and multi-level (walks the cmdb_rel_ci table) | Static joins defined in metadata |
| Target Audience | CMDB Managers, Business Analysts, Admins | Administrators and Developers |
| Non-CMDB Integration | Direct joins via reference fields | Requires manual Database View creation |
| CSDM Alignment | Native support for Dynamic CI Groups and Service maps | Requires complex reporting configurations |
Saved Queries and Platform Integration
Queries built within the Query Builder can be saved for future execution, sharing, or programmatic consumption.
- Storage: Saved queries are stored in the Saved Queries [qb_saved_query] table.
- Sharing: Access can be restricted to the creator, shared with specific groups, or made global.
- Execution and Status: Executing a query creates a record in the Query Status [qb_query_status] table. The platform processes the query in the background if it is complex, preventing browser timeout issues.
- Scheduling: Query execution can be scheduled to run at regular intervals (e.g., daily or weekly), with results exported to CSV/Excel or emailed to stakeholders.
Integration with Dynamic CI Groups
One of the most powerful features of saved queries is their integration with Dynamic CI Groups [cmdb_group].
- CMDB Group Definition: A CMDB Group is a collection of CIs defined by specific criteria.
- Query Association: A CMDB Group can use a saved CMDB query as its population method.
- Automated Maintenance: When CIs are added or updated in the CMDB that match the query criteria, they automatically become members of the group.
- CSDM Alignment: Under the Common Service Data Model (CSDM), Dynamic CI Groups act as the link between technical service offerings and the underlying CIs (e.g., grouping all Linux web servers in a specific data center for patch management).
Advanced Query Types and Settings
The CMDB Query Builder supports several advanced configurations to resolve complex infrastructure layouts:
- No Relationship (Orphaned CIs): By selecting the "No Relationship" option on a connection line, you can identify CIs that should be connected but are missing relationships. For example, finding all Database Instances that do not have a Runs on relationship to any Server. This is a primary tool for CMDB compliance and completeness audits.
- Logical Operators (AND/OR/NOT): Node filters can be combined using complex logical conditions. Additionally, you can create branches from a single node (e.g., a Load Balancer node connecting to both a Linux Server node OR a Windows Server node).
- Properties and Limits: System properties control query behavior, such as the maximum row count returned and query execution timeout limits. For large CMDBs, adjusting these properties avoids performance degradation during peak hours.
Which table is used to store queries authored using the CMDB Query Builder?
How can the output of a saved CMDB Query Builder query be used dynamically within the Common Service Data Model (CSDM) framework?
A CMDB administrator wants to write a query that identifies all Application Servers that do NOT have any 'Runs on' relationships to a physical or virtual host. Which relationship option in the Query Builder connection line should be selected to achieve this?