<h2>Build a CMDB query using the CMDB Query Builder</h2><br/><div style="overflow-x:auto"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta content="text/html; charset=UTF-8" /><meta name="copyright" content="(C) Copyright 2024" /><meta name="DC.rights.owner" content="(C) Copyright 2024" /><meta name="generator" content="DITA-OT" /><meta name="DC.type" content="task" /><meta name="DC.title" content="Build a CMDB query using the CMDB Query Builder" /><meta name="abstract" content="A CMDB query type that queries the infrastructure for CI classes and optionally non-CMDB tables, and the relationships and references that connect them." /><meta name="description" content="A CMDB query type that queries the infrastructure for CI classes and optionally non-CMDB tables, and the relationships and references that connect them." /><meta name="DC.relation" scheme="URI" content="../../../product/configuration-management/concept/querying-cmdb.html" /><meta name="DC.relation" scheme="URI" content="../../../administer/general/concept/capabilities-bundle-landingpage.html" /><meta name="DC.relation" scheme="URI" content="../../../administer/general/concept/manage-cmdb.html" /><meta name="DC.relation" scheme="URI" content="../../../product/configuration-management/concept/c_ITILConfigurationManagement.html" /><meta name="DC.relation" scheme="URI" content="../concept/sample-queries.html" /><meta name="DC.creator" content="ServiceNow" /><meta name="DC.date.created" content="2023-02-02" /><meta name="DC.date.modified" content="2023-02-02" /><meta name="DC.format" content="XHTML" /><meta name="DC.identifier" content="use-cmdb-query-builder" /><link rel="stylesheet" type="text/css" href="../../../CSS/commonltr.css" /><title>Build a CMDB query using the CMDB Query Builder</title></head><body id="use-cmdb-query-builder"> <div class="breadcrumb"><a class="link" href="../../../administer/general/concept/capabilities-bundle-landingpage.html" title="Extend the Now Platform with additional applications and features.">Extend Now Platform capabilities</a> > <a class="link" href="../../../administer/general/concept/manage-cmdb.html" title="The CMDB is a centralized source that gives you full visibility into your IT environment. By storing information about your organization's infrastructure and how it is configured, this system allows you to monitor your network and ensure stability and best performance.">Configuration Management Database (CMDB)</a> > <a class="link" href="../../../product/configuration-management/concept/c_ITILConfigurationManagement.html" title="With the ServiceNow Configuration Management Database (CMDB) application, build logical representations of assets, services, and the relationships between them that comprise the infrastructure of your organization. Details about these components are stored in the CMDB as configuration items (CIs) which you can use to monitor the infrastructure, helping ensure integrity, stability, and continuous service operation.">Managing the CMDB</a> > </div> <h1 class="title topictitle1" id="ariaid-title1">Build a CMDB query using the CMDB Query Builder</h1> <div class="body taskbody"><p class="shortdesc">A CMDB query type that queries the infrastructure for CI classes and optionally non-CMDB tables, and the relationships and references that connect them.</p> <div class="section prereq p"> <p class="p">The <a class="xref" href="../administer/navigation-and-ui/task/t_ActivateUI16.dita/t_ActivateUI16.html" target="_blank" rel="noopener noreferrer">Core UI plugin</a> (com.glide.ui.ui16) must be activated.</p> <p class="p">Role required: cmdb_query_builder_read to only view and run saved queries, and cmdb_query_builder (contained for itil, itil_admin, and asset) to create and save queries, modify saved queries, and run queries.</p> <p class="p">Authorized users can update and <a class="xref" href="delete-cmdb-query.html" title="Delete a CMDB query that is no longer used or needed.">delete</a> a query created by another user.</p> </div> <div class="section context"> <p class="p">Build the query by dragging the CI classes and non-CMDB tables that you want to include in the query. Then dropping them as nodes on the canvas, and defining relationship properties between them. You can filter on the attributes of any node to narrow down the results to a specific set of CIs of that class or to a single specific CI. You can also select which property columns appear in the query results.</p> <p class="p">As you step through building a query, list options and other user interface elements of the CMDB Query Builder, are dynamically filtered as appropriate to your selections.</p> <p class="p">To learn more about using Query Builder, see the <a class="xref" href="https://www.youtube.com/watch?v=NArqszOamHc" target="_blank" rel="noopener noreferrer">CMDB Query Builder Queries and Reporting - Platform Analytics Academy</a> <span class="ph">ServiceNow Community</span> video. For a step-by-step walk through of building CMDB queries in the Query Builder, including queries with application services, see <a class="xref" href="../concept/sample-queries.html" title="Use the following sample queries to build your own CMDB queries and Service Mapping queries.">Sample queries</a>.</p> </div> <ol class="ol steps"><li class="li step stepexpand"> <span class="ph cmd">Navigate to <span class="ph menucascade"><span class="ph uicontrol">All</span> > <span class="ph uicontrol">Configuration</span></span> and click <span class="ph uicontrol">CMDB Query Builder</span>.</span> </li><li class="li step stepexpand"> <span class="ph cmd">On the <span class="ph uicontrol">CMDB Query Builder</span> page do either of the following steps:</span> <ul class="ul choices" id="use-cmdb-query-builder__choices_c2f_3zg_b3b"><li class="li choice">Click <span class="ph uicontrol">Create new</span>. Type in a <span class="ph uicontrol">Name</span>, choose <span class="ph uicontrol">CMDB Query</span> as the <span class="ph uicontrol">Query type</span>, and then click <span class="ph uicontrol">Create</span>.</li><li class="li choice">Click a widget of a saved query to continue building an existing query. <a class="xref" href="search-saved-queries.html" title="The CMDB Query Builder allows you to search for a specific saved query using any combination of search criteria such as the query's name, type, custom tags, and who created or updated the query.">Search saved queries</a> first if needed.</li><li class="li choice">Point to the upper right corner of a saved query widget, and click the <span class="ph uicontrol">Duplicate Query</span> icon to edit a copy of a saved query. The default name of the new query contains the string 'copy'.</li></ul> </li><li class="li step stepexpand"> <span class="ph cmd">On the canvas, you can do any of the following operations:</span> <div class="itemgroup info"> <ul class="ul" id="use-cmdb-query-builder__ul_umc_tjd_rw"><li class="li">Add CI classes to the query: On the <span class="ph uicontrol">CMDB Classes</span> tab, select classes from the hierarchy list and drag them to the canvas.</li><li class="li"><p class="p">Add an Application Service CI to the query: On the <span class="ph uicontrol">CMDB Classes</span> tab, select the <span class="ph uicontrol">Application Service</span> class from the hierarchy list and drag it to the canvas.</p> <p class="p">In Application Service Properties on the right-side bar, you can select <span class="ph uicontrol">Convert attached nodes to pattern</span> to query on patterns between the application service and other CMDB class nodes. When querying on a pattern, the nodes on both ends of the pattern connection, can be any number of levels apart. If <span class="ph uicontrol">Convert attached nodes to pattern</span> is not selected, then the connection between the application service node and other CMDB class nodes, represent direct relationships.</p> </li><li class="li">Add non-CMDB tables to the query: Select a table from the <span class="ph uicontrol">Non-CMDB Tables</span> list and drag it to the canvas. <div class="note"><span class="notetitle">Note:</span> A non-CMDB table cannot be the starting node in the query.</div> </li><li class="li"><div class="p">Add connections (relationships or patterns for application services) between two nodes on the canvas:<ol class="ol" type="a" id="use-cmdb-query-builder__ol_ig1_fw5_plb"><li class="li">On the first node in the connection, click the small square at the center of the right side.</li><li class="li">On the second node in the connection, click the small square at the center of the left side to create the connection.</li></ol> </div> <div class="p"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="use-cmdb-query-builder__table_ipf_qw5_plb" class="table" frame="border" border="1" rules="all"><caption><span class="tablecap"><span class="table--title-label">Table 1. </span>Connection UI Notations</span></caption><colgroup><col style="width:50%" /><col style="width:50%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d738394e216">Notation</th><th class="entry cellrowborder" style="vertical-align:top;" id="d738394e219">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d738394e216 ">Full line</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d738394e219 ">A relationship in a CMDB query.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d738394e216 ">Red asterisk at the center of the connection line</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d738394e219 ">Information such as relationship type is missing, invalidating the query.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d738394e216 "><span class="ph uicontrol">Levels:<n> Types:<n></span> or a <span class="ph uicontrol"><Reference type></span> notation on the connection line</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d738394e219 "><p class="p">As applicable: The number of relationship levels and the number of relationship types included for the connection. Or, a reference type for a relationship that is a reference.</p> </td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d738394e216 ">Dashed line</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d738394e219 ">A pattern connection between an application service node and another node.</td></tr></tbody></table> </div> </div> </li><li class="li">In Connection Properties on the right-side bar, configure relationship settings (click the connection line if necessary):<ol class="ol" type="a" id="use-cmdb-query-builder__ol_mb1_xld_rw"><li class="li">In the Relationship Direction section, select the <span class="ph uicontrol">Parent</span> node (the <span class="ph uicontrol">Child</span> node automatically adjusts).</li><li class="li">In the Relationship Levels section, set <span class="ph uicontrol">Level</span> to <span class="ph uicontrol">First level relationships</span> if the CIs are directly connected. Or, <span class="ph uicontrol">Up to 2nd level relationships</span> if the CIs are connected either directly or indirectly through another CI.</li><li class="li"><div class="p">In the Relationship Types and Related Items section, select either option: <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="use-cmdb-query-builder__table_xsh_c1h_b3b" class="table" frame="border" border="1" rules="all"><colgroup><col style="width:50%" /><col style="width:50%" /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d738394e311">Option</th><th class="entry cellrowborder" style="vertical-align:top;" id="d738394e314">Description</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d738394e311 "><span class="ph uicontrol">No Relationships</span></td><td class="entry cellrowborder" style="vertical-align:top;" headers="d738394e314 ">To query for CIs with no connecting relationships, such as <code class="ph codeph">All Tomcat WAR CIs which are not connected to a Windows Server</code>.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d738394e311 "><span class="ph uicontrol">Add Relationship Types</span></td><td class="entry cellrowborder" style="vertical-align:top;" headers="d738394e314 ">To select specific or any relationship type.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d738394e311 "><span class="ph uicontrol">Add a Related Item</span></td><td class="entry cellrowborder" style="vertical-align:top;" headers="d738394e314 ">To query for related CIs between the nodes.</td></tr></tbody></table> </div> </div> </li></ol> </li><li class="li">Configure CI reference column for a connection to a non-CMDB table: In the Connection Properties right-side bar, in the CI Reference Column section, select the column with a reference to a CI from the <span class="ph uicontrol">Use CI reference column</span> list. If only one option is available, it is automatically selected.</li><li class="li">Configure the pattern between an application service node set with the <span class="ph uicontrol">Convert attached nodes to pattern</span> option, and a non-CMDB table node: Select <span class="ph uicontrol">Apply <table> reference filter to all nodes in the pattern</span> to apply the query to the application service CI itself and to the CIs within the application service.</li><li class="li">Add filters to a class node: Apply filters to narrow down a class query to a specific set of CIs or to a single specific CI.<div class="p"><ol class="ol" type="a" id="use-cmdb-query-builder__ol_s2b_nnd_rw"><li class="li">Point to the node to add a filter to, and then click the <span class="ph uicontrol">Apply filters</span> icon that pops up above the node.</li><li class="li">In the Filters section, add attribute and <a class="xref" href="../use/using-lists-v3/task/create-related-list-query.dita/create-related-list-query.html" target="_blank" rel="noopener noreferrer">related list conditions</a>.</li><li class="li">Close the <span class="ph uicontrol">Filters</span> section.</li></ol> For example: Add a filter for database location to query for databases located in Seattle.</div> <p class="p">Click <span class="ph uicontrol">Applied Filters</span> in the right-side bar to view all filters for each node on the canvas.</p> </li><li class="li">Add And/Or operators to the query: <div class="p"><ol class="ol" type="a" id="use-cmdb-query-builder__ol_uyd_3vp_rw"><li class="li">Connect one node to two other nodes.</li><li class="li">Click the <span class="ph uicontrol">And</span> box that appears on the connection line, to toggle between the <span class="ph uicontrol">And</span>/<span class="ph uicontrol">Or</span> operators.</li></ol> For example: C1 is Tomcat WAR, C2 is Linux Server, and C3 is Windows Server. Query for <code class="ph codeph">All Tomcat WAR CIs which are connected either to Linux Server Or to a Windows Server</code>.</div> </li><li class="li">Add property columns for a node, to appear in the query results:<div class="note"><span class="notetitle">Note:</span> For a relationship, the query results include the <span class="keyword parmname">parent</span>, <span class="keyword parmname">child</span>, and <span class="keyword parmname">type</span> columns. You cannot add any other columns from the [cmdb_rel_ci] table.</div> <ol class="ol" type="a" id="use-cmdb-query-builder__ol_bhh_3qd_rw"><li class="li">Click <span class="ph uicontrol">Properties</span> in the right-side pane.</li><li class="li">Click a node once or twice, so that the Report Columns section appears in the right-side bar, and then click <span class="ph uicontrol">Add Columns</span>.</li><li class="li">Select properties and then click outside the properties list to close it.</li></ol> </li><li class="li">Create a combination query by integrating a <span class="ph">Service Mapping</span> query into a CMDB query: <div class="p"><ol class="ol" type="a" id="use-cmdb-query-builder__ol_zlh_lgh_hx"><li class="li">When building a CMDB query, click <span class="ph uicontrol">Saved Service Queries</span> in the left-side bar.</li><li class="li">Select and then drag a <span class="ph">Service Mapping</span> query to the canvas.</li></ol> This query returns all CIs that satisfy the CMDB query, and that are included in the services returned by the embedded <span class="ph">Service Mapping</span> query.</div> </li><li class="li">Add a search tag that can then be used as a search criteria for saved queries:<ol class="ol" type="a" id="use-cmdb-query-builder__ol_sm5_1pb_4y"><li class="li">Click the <span class="ph uicontrol">Add Tags</span> icon at the top of the canvas.</li><li class="li">Click <span class="ph uicontrol">Add Tag</span> and in the <span class="ph uicontrol">Query Tags</span> dialog box enter one or more tag strings.</li><li class="li">Click the <span class="ph uicontrol">Add Tags</span> icon again to close the <span class="ph uicontrol">Query Tags</span> dialog box.</li></ol> </li></ul> </div> </li><li class="li step stepexpand"> <span class="ph cmd">Click <span class="ph uicontrol">Save</span>.</span> <div class="itemgroup info"> <p class="p">On the <span class="ph uicontrol">Saved Queries</span> tab, point to a saved query widget and click <span class="ph uicontrol">Query Information</span>. Query details such as the query type, last update date, CMDB groups associated with the query, and the query schedules appear.</p> </div> </li></ol> <div class="section postreq"> <ul class="ul" id="use-cmdb-query-builder__ul_jhq_hdx_rw"><li class="li"><p class="p">Click <span class="ph uicontrol">Run</span>.</p> <div class="p">Only the first 100 results of the query appear in the results pane.<ul class="ul" id="use-cmdb-query-builder__ul_gfw_42t_w1b"><li class="li">Click <span class="ph uicontrol">Load More Results</span> to view the next set of 100 results.</li><li class="li">Click <span class="ph uicontrol">Load All Results</span> to view the rest of the query results, up to the number specified by the <a class="xref" href="../reference/cmdb-querybldr-sysproprties.html" title="Use the CMDB Query Builder properties to configure query processing.">glide.cmdb.query.max_results_limit</a> system property (10,000 by default).</li></ul> </div> <p class="p">Click a CI to open its CI form, and on the CI form click <span class="ph uicontrol">Dashboard</span> to view CI health in the CI dashboard.</p> <div class="note"><span class="notetitle">Note:</span> <ul class="ul" id="use-cmdb-query-builder__ul_f44_jyr_mfb"><li class="li">Ensure that the <a class="xref" href="../administer/security/reference/anti-csrf-token.dita/anti-csrf-token.html" target="_blank" rel="noopener noreferrer">glide.security.use_csrf_token</a> property is set to true, allowing all results to appear.</li><li class="li">When <span class="ph uicontrol">Level</span> is set to <span class="ph uicontrol">Up to 2nd level relationships</span>, the relationship type does not appear in the query results.</li><li class="li">When a query is running, wait for it to complete or to time out before opening or running another query.</li></ul> </div> </li><li class="li"><a class="xref" href="../reference/cmdb-query-builder-settings.html" title="Use settings to control some aspects of the CMDB Query Builder behavior.">Modify Query Builder settings</a>: Click the <img class="image icon" id="use-cmdb-query-builder__image_x3w_sfg_nfb" height="20" src="../../business-service-management-map-ng/image/dv-map-settings.png" alt="Settings icon." /> (<span class="ph uicontrol">Settings</span>) icon to open the <span class="ph uicontrol">Query Builder Settings</span> dialog box.</li><li class="li">Copy and share the URL of a saved query with users that have access to the CMDB Query Builder. Pasting the shared URL in a new internet browser window, directly opens the saved query in the CMDB Query Builder.</li><li class="li"><a class="xref" href="../concept/create-query-results-report.html" title="Use CMDB Query Builder reports to show the results of a CMDB query or a Service Mapping query. Create a basic report, or a dynamic report that automatically updates when the results of the associated saved query change.">Create reports in CMDB Query Builder</a>.</li><li class="li"><a class="xref" href="create-cmdb-query-schedule.html" title="Schedule a saved CMDB query to run once at a scheduled time or on a recurring schedule, and to email the query results to specified users.">Create a schedule</a> to run the query at a future time, and to email the results to interested parties.</li><li class="li">Export query results: <p class="p">Click the Query Results context menu and select <span class="ph uicontrol">Export</span>. Even if the <span class="ph uicontrol">Load More Results</span> button is visible, indicating that there are additional query results, only the results that are visible are exported.</p> </li><li class="li"><a class="xref" href="export-import-query.html" title="Export a saved CMDB or Service Mapping query definition to an XML file which you can later import and run in the CMDB Query Builder. This process lets you port a saved query between instances, such as from a development environment to a production environment.">Export and import a CMDB query</a> to port a query definition between instances.</li><li class="li"><a class="xref" href="../concept/cmdb-groups.html#populate-cmdb-grp-saved-query" title="Depending on the group type, you can populate a CMDB group by manually adding individual CIs, selecting saved CMDB queries, or building encoded queries in the CMDB group itself. The resulting CIs from each query are added as members to the group.">Populate a CMDB group</a> using a saved query.</li><li class="li"><a class="xref" href="delete-cmdb-query.html" title="Delete a CMDB query that is no longer used or needed.">Delete a CMDB query</a>.</li></ul> </div> </div> <div class="related-links"> <div class="familylinks"> <div class="parentlink"><strong>Parent Topic:</strong> <a class="link" href="../../../product/configuration-management/concept/querying-cmdb.html" title="The CMDB Query Builder allows you to easily build complex infrastructure and service queries, that span multiple CMDB classes, non-CMDB tables, and that involve many CIs that are connected by different relationships.">Querying the CMDB</a></div> </div> <div class="linklist relinfo relconcepts"><strong>Related concepts</strong><br /> <ul class="linklist"><li class="linklist"><a class="link" href="../concept/sample-queries.html" title="Use the following sample queries to build your own CMDB queries and Service Mapping queries.">Sample queries</a></li></ul></div> </div> </body></html></div>