{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":714,"path":"api-reference/server-api-reference/CMDBQueryBuilderAPI.md","title":"CMDBQueryBuilderAPI - Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# CMDBQueryBuilderAPI- Global\n\nProvides methods to execute Configuration Management Database \\(CMDB\\) Query Builder operations in server-side scripts.\n\nThis API requires the Configuration Management Database \\(CMDB\\) application \\(com.snc.cmdb\\).\n\n**Note:**\n\nThis API is only available in Global scope. To use these methods in a scoped application, see [CMDBQBScopedScriptableAPI - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CMDBQBScopedAPI.md).\n\nFor more information about CMDB Query Builder, see [CMDB Query Builder](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/cmdb-query-builder-landing-page.md).\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## CMDBQueryBuilderAPI - createReport\\(String savedQueryId, String savedQueryName\\)\n\nCreates a report that shows the results of a Configuration Management Database \\(CMDB\\) Query Builder query and returns the URL of the report.\n\nFor scoped applications, use [CMDBQBScopedScriptableAPI - createReport\\(String savedQueryId, String savedQueryName\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CMDBQBScopedAPI.md).\n\n<table id=\"id_dv4_sps_pbc\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nsavedQueryId\n\n</td><td>\n\nString\n\n</td><td>\n\nSys\\_id of the query to use for the report.This parameter is not required if a query name is provided.\n\nTable: Saved Queries \\[qb\\_saved\\_query\\]\n\n</td></tr><tr><td>\n\nsavedQueryName\n\n</td><td>\n\nString\n\n</td><td>\n\nName of the query to use for the report.This parameter is not required if a query sys\\_id is provided.\n\nTable: Saved in the **Name** field of the Saved Queries \\[qb\\_saved\\_query\\] table.\n\n</td></tr></tbody>\n</table><table id=\"id_tbd_tps_pbc\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject\n\n</td><td>\n\nDetails about the created report and any errors.```\n{\n  \"error\": \"String\",\n  \"message\": \"String\",\n  \"status\": \"String\"\n}\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.error\n\n</td><td>\n\nError code. Returned when the report creation fails or invalid input parameters are provided. Possible errors:\n\n-   `USER_NOT_AUTHORIZED_EXCEPTION`\n-   `INVALID_PARAM`\n-   `QUERY_SYS_ID_INVALID`\n-   `REPORT_INELIGIBLE`\n\nData type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.message\n\n</td><td>\n\nMessage containing details about the success or failure of the report creation.Possible messages:\n\n-   `<report-url>`\n-   `User is unauthorized to create a CMDBQueryBuilder query report`\n-   `Invalid Parameters. Please provide either a valid sysId or a valid name of a saved query`\n-   `Invalid queryId. Please provide a valid saved query ID`\n-   `Query must have a schedule with at least one run to create a report.`\n\nSee also [Schedule a CMDB query](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/create-cmdb-query-schedule.md).\n\nData type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.status\n\n</td><td>\n\nStatus code. Returned when the update is successful.Value: `success`\n\nData type: String\n\n</td></tr></tbody>\n</table>This example shows how to create a report by passing a saved query name.\n\n```\nvar queryReport = SNC.CMDBQueryBuilderAPI.createReport('', 'CMDBQueryTest1');\n\ngs.info(JSON.stringify(JSON.parse(queryReport), null, 2));\n```\n\nOutput:\n\n```\n{\n   \"message\":\"\\/sys_report_template.do?sysparm_report_source_id=6d299cf81bbd4210bccf42a3b24bcb7a&sysparm_type=list&sysparm_title=CMDBQueryTest1&sysparm_source_type=source&sysparm_from_list=true&sysparm_chart_size=large&sysparm_manual_labor=true\",\n   \"status\":\"success\"\n}\n```\n\nThis example shows an error when the provided query name is invalid.\n\n```\nvar queryReport = SNC.CMDBQueryBuilderAPI.createReport('', 'Test');\n\ngs.info(JSON.stringify(JSON.parse(queryReport), null, 2));\n```\n\nOutput:\n\n```\n{\n   \"error\":\"INVALID_PARAM\",\n   \"message\":\"Invalid Parameters. Please provide either a valid sysId or a valid name of a saved query\"\n}\n```\n\n## CMDBQueryBuilderAPI - deleteQuery\\(String savedQueryId, String savedQueryName\\)\n\nDeletes a Configuration Management Database \\(CMDB\\) Query Builder query.\n\nFor scoped applications, use [CMDBQBScopedScriptableAPI - deleteQuery\\(String savedQueryId, String savedQueryName\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CMDBQBScopedAPI.md).\n\n<table id=\"id_smz_nqs_pbc\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nsavedQueryId\n\n</td><td>\n\nString\n\n</td><td>\n\nSys\\_id of the query to delete.This parameter can be provided as an empty string if a query name is provided.\n\nTable: Saved Queries \\[qb\\_saved\\_query\\]\n\n</td></tr><tr><td>\n\nsavedQueryName\n\n</td><td>\n\nString\n\n</td><td>\n\nName of the query to delete.This parameter is not required if a query sys\\_id is provided.\n\nTable: Saved in the *Name* field of the Saved Queries \\[qb\\_saved\\_query\\] table.\n\n</td></tr></tbody>\n</table><table id=\"id_ekn_4qs_pbc\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject\n\n</td><td>\n\nDetails about the deleted query and any errors.```\n{\n  \"error\": \"String\",\n  \"message\": \"String\",\n  \"status\": \"String\"\n}\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.error\n\n</td><td>\n\nError code. Returned when the delete operation fails or invalid input parameters are provided. Possible errors:\n\n-   `USER_NOT_AUTHORIZED_EXCEPTION`\n-   `INVALID_PARAM`\n-   `QUERY_DELETE_FAILED`\n\nData type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.message\n\n</td><td>\n\nMessage containing details about the success or failure of the delete operation.Possible messages:\n\n-   `Successfully deleted the saved query`\n-   `User is unauthorized to delete a CMDBQueryBuilder query`\n-   `Invalid Parameters. Please provide either a valid sysId or a valid name of a saved query`\n-   `Failed to delete the given saved query`\n\nData type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.status\n\n</td><td>\n\nStatus code. Returned when the update is successful.Value: `success`\n\nData type: String\n\n</td></tr></tbody>\n</table>This example shows how to delete a saved query by passing the query name.\n\n```\nvar delQuery = SNC.CMDBQueryBuilderAPI.deleteQuery('', 'CMDBQueryTest1');\n\ngs.info(JSON.stringify(JSON.parse(delQuery), null, 2));\n```\n\nOutput:\n\n```\n{\n   \"message\":\"Successfully deleted the saved query\",\n   \"status\":\"success\"\n}\n```\n\n## CMDBQueryBuilderAPI - getSavedQueryExecutionDetails\\(String savedQueryName, Boolean executeQuery, Number timeout\\)\n\nReturns the execution details for a Configuration Management Database \\(CMDB\\) Query Builder query.\n\nOptionally, you can execute the query in order to return current execution details.\n\nIf a timeout or memory issue occurs while executing the query, you can fine tune the query batch size to help alleviate these problems. For more information, see [Batch size for Query Builder saved queries](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/batch-size-query.md).\n\nFor scoped applications, use [CMDBQBScopedScriptableAPI - getSavedQueryExecutionDetails\\(String savedQueryName, Boolean executeQuery, Number timeout\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CMDBQBScopedAPI.md).\n\n<table id=\"id_ezv_4vz_pbc\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nsavedQueryName\n\n</td><td>\n\nString\n\n</td><td>\n\nName of the query to retrieve execution details for. Table: *Name* field in the Saved Queries \\[qb\\_saved\\_query\\] table.\n\n</td></tr><tr><td>\n\nexecuteQuery\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nOptional. Flag that indicates whether to execute the specified query.Valid values:\n\n-   true: Execute the specified query and return its execution details.\n-   false: Don't execute the specified query. Return the most recent execution details for the query.\n\nDefault: False\n\n</td></tr><tr><td>\n\ntimeout\n\n</td><td>\n\nNumber\n\n</td><td>\n\nOptional. Integer value that overrides the default query execution timeout limit of five minutes.Unit: Seconds\n\nDefault: Five minutes\n\n</td></tr></tbody>\n</table><table id=\"id_wyc_pvz_pbc\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject\n\n</td><td>\n\nDetails about the query execution and any errors.```\n{\n  \"error\": \"String\",\n  \"execution_batch_size\": Number,\n  \"message\": \"String\",\n  \"query_id\": \"String\",\n  \"status\": \"String\",\n  \"table_name\": \"String\"\n}\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.error\n\n</td><td>\n\nError code. Returned when the query execution fails or the specified query is not found.Possible errors:\n\n-   `QUERY_EXECUTION_NOT_FOUND`\n-   `QUERY_NOT_FOUND`\n-   `QUERY_EXECUTION_FAILED`\n-   `USER_NOT_AUTHORIZED_EXCEPTION`\n\nData type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.execution\\_batch\\_size\n\n</td><td>\n\nBatch size of 100 allocated for the query run. This value only returns if the **executeQuery** parameter is true. See also [Batch size for CMDB Query Builder queries](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/batch-size-query.md).Data type: Number\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.message\n\n</td><td>\n\nMessage containing details about the error code. Returned when the query execution fails or the specified query is not found.Possible messages:\n\n-   `Query execution details not found. Please execute the query.`\n-   `Given saved query not found. Please make sure you are passing the name of a saved query.`\n-   `Query execution failed. Please use a valid query.`\n-   `User is unauthorized to execute a CMDBQueryBuilder query.`\n\nData type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.query\\_id\n\n</td><td>\n\nSys\\_id of the query execution.Data type: String\n\nTable: Query Status \\[qb\\_query\\_status\\]\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.status\n\n</td><td>\n\nStatus of the query execution.-   COMPLETE: Execution is complete.\n-   FAILED: Error occurred while executing query.\n-   TIME\\_OUT: Query execution timed out.\n-   MAX\\_LIMIT: Maximum number of return results reached.\n\nData type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.table\\_name\n\n</td><td>\n\nName of the table that contains the query execution details.Data type: String\n\n</td></tr></tbody>\n</table>This example shows how to get the execution status of a saved query.\n\n```\nvar savedQuery = SNC.CMDBQueryBuilderAPI.getSavedQueryExecutionDetails('CMDBQueryTest1');\n\ngs.info(JSON.stringify(JSON.parse(savedQuery), null, 2));\n```\n\nOutput:\n\n```\n{\n   \"query_id\":\"024fd53a7773330033b5270bba106141\",\n   \"table_name\":\"u_cmdb_qb_result_598918aacb4dbf3f1a8dcf03fce6a5d57151a4e2\",\n   \"status\":COMPLETE\n}\n```\n\nThis example shows how to execute a saved query and set the query execution timeout value to 10 minutes.\n\n```\nvar savedQuery = SNC.CMDBQueryBuilderAPI.getSavedQueryExecutionDetails('CMDBQueryTest2', true, 600);\n\ngs.info(JSON.stringify(JSON.parse(savedQuery), null, 2));\n```\n\nOutput:\n\n```\n{\n  \"execution_batch_size\": 100,\n  \"query_id\": \"e73428b4939baa50779bfdfb5cba1047\",\n  \"table_name\": \"u_cmdb_qb_result_f0eed95be923bf3d439c87c028ae3c3af53aa739\",\n  \"status\": \"COMPLETE\"\n}\n```\n\nThe following example shows how to access information in the result table for the saved query CMDBQueryTest2 in the previous example. You can also use the result table name followed by `.list` in the filter for results.\n\n```\nvar resultTableName = 'u_cmdb_qb_result_f7593958e298869427726be96f88155cce269806';\nvar queryId = '76bd283c931bee502285f4cc5cba10da'; // insert the query ID here\nvar gr = new GlideRecord(resultTableName);\ngr.addQuery('query', queryId);\ngr.query();\nif (gr.next()) { \n     gs.info(gr.getDisplayValue('u_server_1')); // field name in the result table\n}\n```\n\nOutput:\n\n```\nPS LoadBal01\n```\n\n## CMDBQueryBuilderAPI - saveQuery\\(String savedQueryName, String queryJson\\)\n\nSaves a Configuration Management Database \\(CMDB\\) Query Builder query and returns the sys\\_id of the saved query.\n\nFor scoped applications, use [CMDBQBScopedScriptableAPI - saveQuery\\(String savedQueryName, String queryJson\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CMDBQBScopedAPI.md).\n\n<table id=\"id_dzn_1v5_pbc\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr id=\"save-query-name\"><td>\n\nsavedQueryName\n\n</td><td>\n\nString\n\n</td><td>\n\nName to save the query under. Table: Saved in the **Name** field of the Saved Queries \\[qb\\_saved\\_query\\] table.\n\n</td></tr><tr id=\"save-query-json\"><td>\n\nqueryJson\n\n</td><td>\n\nString\n\n</td><td>\n\nJSON that defines the query.Table: Saved in the **Query** field of the Saved Queries \\[qb\\_saved\\_query\\] table.\n\n</td></tr></tbody>\n</table><table id=\"id_d3f_bv5_pbc\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject\n\n</td><td>\n\nObject containing details about the saved query and any errors.```\n{\n   \"error\": \"String\",\n   \"message\": \"String\",\n   \"status\": \"String\"\n}\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.error\n\n</td><td>\n\nError code. Returned when the save operation fails or invalid input parameters are provided. Possible errors:\n\n-   `USER_NOT_AUTHORIZED_EXCEPTION`\n-   `QUERY_NAME_INVALID`\n-   `QUERY_INVALID`\n-   `QUERY_EXISTS_ALREADY`\n-   `QUERY_SAVE_FAILED`\n\nData type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.message\n\n</td><td>\n\nMessage containing details about the success or failure of the save operation. Possible messages:\n\n-   `Successfully saved the query with sysId <sy_id>`\n-   `User is unauthorized to save a CMDBQueryBuilder query`\n-   `Query name is empty. Please provide a name`\n-   `QueryJson is invalid. Please provide a valid queryJson`\n-   `Query name is already used, please use a different name`\n-   `Unexpected exception while saving the query`\n\nData type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.status\n\n</td><td>\n\nStatus code. Returned when the save operation is successful.Value: `success`\n\nData type: String\n\n</td></tr></tbody>\n</table>This example shows how to add a query to the Saved Queries \\[qb\\_saved\\_query\\] table.\n\n```\nvar queryJson = \"{\\\"type\\\":\\\"cmdb\\\",\\\"nodes\\\":[{\\\"label\\\":\\\"Server\\\",\\\"unique_id\\\":\\\"d93f96981b310210bccf42a3b24bcb41\\\",\\\"nodeType\\\":\\\"class\\\",\\\"image\\\":\\\"images/app.ngbsm/server.svg\\\",\\\"properties\\\":\\\"\\\",\\\"allowed_connections\\\":[],\\\"filters\\\":{\\\"platform\\\":\\\"cmdb_ci_server\\\",\\\"custom\\\":\\\"\\\"},\\\"ci_type\\\":\\\"cmdb_ci_server\\\",\\\"ci_type_label\\\":\\\"Server\\\",\\\"sys_id\\\":\\\"d93f96981b310210bccf42a3b24bcb41\\\",\\\"x\\\":72,\\\"y\\\":337,\\\"returnValues\\\":[],\\\"filters_attrib\\\":\\\"\\\",\\\"applied_filters\\\":\\\"\\\",\\\"isStartNode\\\":true,\\\"nodeId\\\":\\\"d93f96981b310210bccf42a3b24bcb41_4_23_2024_5_50_54\\\",\\\"name\\\":\\\"Server 1\\\",\\\"type\\\":\\\"class\\\",\\\"refFilterApplied\\\":false,\\\"focused\\\":false,\\\"id\\\":\\\"d93f96981b310210bccf42a3b24bcb41_4_23_2024_5_50_54\\\",\\\"className\\\":\\\"cmdb_ci_server\\\"},{\\\"label\\\":\\\"Database\\\",\\\"unique_id\\\":\\\"b640269c1b310210bccf42a3b24bcb36\\\",\\\"nodeType\\\":\\\"class\\\",\\\"image\\\":\\\"images/app.ngbsm/database.svg\\\",\\\"properties\\\":\\\"\\\",\\\"allowed_connections\\\":[],\\\"filters\\\":{\\\"platform\\\":\\\"cmdb_ci_database\\\",\\\"custom\\\":\\\"\\\"},\\\"ci_type\\\":\\\"cmdb_ci_database\\\",\\\"ci_type_label\\\":\\\"Database\\\",\\\"sys_id\\\":\\\"b640269c1b310210bccf42a3b24bcb36\\\",\\\"x\\\":510,\\\"y\\\":340,\\\"returnValues\\\":[],\\\"filters_attrib\\\":\\\"\\\",\\\"applied_filters\\\":\\\"\\\",\\\"isStartNode\\\":false,\\\"nodeId\\\":\\\"b640269c1b310210bccf42a3b24bcb36_4_23_2024_5_50_57\\\",\\\"name\\\":\\\"Database 1\\\",\\\"type\\\":\\\"class\\\",\\\"refFilterApplied\\\":false,\\\"focused\\\":false,\\\"id\\\":\\\"b640269c1b310210bccf42a3b24bcb36_4_23_2024_5_50_57\\\",\\\"className\\\":\\\"cmdb_ci_database\\\"}],\\\"edges\\\":[{\\\"id\\\":\\\"Server 1_Database 1\\\",\\\"from\\\":\\\"d93f96981b310210bccf42a3b24bcb41_4_23_2024_5_50_54\\\",\\\"to\\\":\\\"b640269c1b310210bccf42a3b24bcb36_4_23_2024_5_50_57\\\",\\\"isDotted\\\":false,\\\"type\\\":\\\"relation\\\",\\\"isReverse\\\":false,\\\"direction\\\":\\\"outbound\\\",\\\"hiddenLevel\\\":0,\\\"relations\\\":[\\\"607ad1b2c0a8010e01941856b365af90\\\",\\\"1a9cb166f1571100a92eb60da2bce5c5\\\"]}],\\\"usedNames\\\":{\\\"cmdb_ci_server\\\":1,\\\"cmdb_ci_database\\\":1}}\";\n\nvar newQuery = SNC.CMDBQueryBuilderAPI.saveQuery('CMDBQueryTest1', queryJson);\n\ngs.info(JSON.stringify(JSON.parse(newQuery), null, 2));\n```\n\nOutput:\n\n```\n{\n   \"message\":\"Successfully saved the query with sysId d93f96981b310210bccf42a3b24bcb41\",\n   \"status\":\"success\"\n}\n```\n\n## CMDBQueryBuilderAPI - updateQuery\\(String savedQueryId, String savedQueryName, String queryJson\\)\n\nUpdates the JSON for a Configuration Management Database \\(CMDB\\) Query Builder query.\n\nFor scoped applications, use [CMDBQBScopedScriptableAPI - updateQuery\\(String savedQueryId, String savedQueryName, String queryJson\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CMDBQBScopedAPI.md).\n\n<table id=\"id_s3p_mv5_pbc\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nsavedQueryId\n\n</td><td>\n\nString\n\n</td><td>\n\nSys\\_id of the query to update.This parameter is not required if a query name is provided.\n\nTable: Saved Queries \\[qb\\_saved\\_query\\]\n\n</td></tr><tr><td>\n\nsavedQueryName\n\n</td><td>\n\nString\n\n</td><td>\n\nName of the query to update.This parameter is not required if a query sys\\_id is provided.\n\nTable: Saved in the *Name* field in the Saved Queries \\[qb\\_saved\\_query\\] table.\n\n</td></tr><tr><td>\n\nqueryJson\n\n</td><td>\n\nString\n\n</td><td>\n\nJSON to update the query with.Table: Saved in the *Query* field in the Saved Queries \\[qb\\_saved\\_query\\] table.\n\n</td></tr></tbody>\n</table><table id=\"id_opl_4v5_pbc\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject\n\n</td><td>\n\nDetails about the updated query and any errors.```\n{\n  \"error\": \"String\",\n  \"message\": \"String\",\n  \"status\": \"String\"\n}\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.error\n\n</td><td>\n\nError code. Returned when the update fails or invalid input parameters are provided. Possible errors:\n\n-   `USER_NOT_AUTHORIZED_EXCEPTION`\n-   `INVALID_PARAM`\n-   `QUERY_INVALID`\n-   `QUERY_UPDATE_FAILED`\n-   `UNAUTHORIZED_REPORT_SOURCE_USER`\n\nData type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.message\n\n</td><td>\n\nMessage containing details about the success or failure of the update. Possible messages:\n\n-   `Successfully updated the saved query`\n-   `User is unauthorized to update a CMDBQueryBuilder query`\n-   `Invalid Parameters. Please provide either a valid sysId or a valid name of a saved query`\n-   `QueryJson is invalid. Please provide a valid queryJson`\n-   `Failed to update the given saved query`\n-   `User is unauthorized to update report source of a saved query`\n\nData type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.status\n\n</td><td>\n\nStatus code. Returned when the update is successful.Value: `success`\n\nData type: String\n\n</td></tr></tbody>\n</table>This example shows how to update a saved query by passing the query name.\n\n```\nvar queryJson = \"{\\\"type\\\":\\\"cmdb\\\",\\\"nodes\\\":[{\\\"label\\\":\\\"Server\\\",\\\"unique_id\\\":\\\"d93f96981b310210bccf42a3b24bcb41\\\",\\\"nodeType\\\":\\\"class\\\",\\\"image\\\":\\\"images/app.ngbsm/server.svg\\\",\\\"properties\\\":\\\"\\\",\\\"allowed_connections\\\":[],\\\"filters\\\":{\\\"platform\\\":\\\"cmdb_ci_server\\\",\\\"custom\\\":\\\"\\\"},\\\"ci_type\\\":\\\"cmdb_ci_server\\\",\\\"ci_type_label\\\":\\\"Server\\\",\\\"sys_id\\\":\\\"d93f96981b310210bccf42a3b24bcb41\\\",\\\"x\\\":72,\\\"y\\\":336,\\\"returnValues\\\":[],\\\"filters_attrib\\\":\\\"\\\",\\\"applied_filters\\\":\\\"\\\",\\\"isStartNode\\\":true,\\\"nodeId\\\":\\\"d93f96981b310210bccf42a3b24bcb41_4_23_2024_5_50_54\\\",\\\"name\\\":\\\"Server 1\\\",\\\"type\\\":\\\"class\\\",\\\"refFilterApplied\\\":false,\\\"focused\\\":false,\\\"id\\\":\\\"d93f96981b310210bccf42a3b24bcb41_4_23_2024_5_50_54\\\",\\\"className\\\":\\\"cmdb_ci_server\\\"},{\\\"label\\\":\\\"Web Server\\\",\\\"unique_id\\\":\\\"984f5a981b310210bccf42a3b24bcb03\\\",\\\"nodeType\\\":\\\"class\\\",\\\"image\\\":\\\"images/app.ngbsm/web_server.svg\\\",\\\"properties\\\":\\\"\\\",\\\"allowed_connections\\\":[],\\\"filters\\\":{\\\"platform\\\":\\\"cmdb_ci_web_server\\\",\\\"custom\\\":\\\"\\\"},\\\"ci_type\\\":\\\"cmdb_ci_web_server\\\",\\\"ci_type_label\\\":\\\"Web Server\\\",\\\"sys_id\\\":\\\"984f5a981b310210bccf42a3b24bcb03\\\",\\\"x\\\":446,\\\"y\\\":330,\\\"returnValues\\\":[],\\\"filters_attrib\\\":\\\"\\\",\\\"applied_filters\\\":\\\"\\\",\\\"isStartNode\\\":false,\\\"nodeId\\\":\\\"984f5a981b310210bccf42a3b24bcb03_4_23_2024_6_32_19\\\",\\\"name\\\":\\\"Web Server 1\\\",\\\"type\\\":\\\"class\\\",\\\"refFilterApplied\\\":false,\\\"focused\\\":false,\\\"id\\\":\\\"984f5a981b310210bccf42a3b24bcb03_4_23_2024_6_32_19\\\",\\\"className\\\":\\\"cmdb_ci_web_server\\\"}],\\\"edges\\\":[{\\\"id\\\":\\\"Server 1_Web Server 1\\\",\\\"from\\\":\\\"d93f96981b310210bccf42a3b24bcb41_4_23_2024_5_50_54\\\",\\\"to\\\":\\\"984f5a981b310210bccf42a3b24bcb03_4_23_2024_6_32_19\\\",\\\"isDotted\\\":false,\\\"type\\\":\\\"relation\\\",\\\"isReverse\\\":false,\\\"direction\\\":\\\"outbound\\\",\\\"hiddenLevel\\\":0,\\\"relations\\\":[\\\"607ad1b2c0a8010e01941856b365af90\\\"]}],\\\"usedNames\\\":{\\\"cmdb_ci_server\\\":1,\\\"cmdb_ci_database\\\":1,\\\"cmdb_ci_web_server\\\":1}}\";\n\nvar queryUpdate = SNC.CMDBQueryBuilderAPI.updateQuery('', 'CMDBQueryTest1', queryJson);\n\ngs.info(JSON.stringify(JSON.parse(queryUpdate), null, 2));\n```\n\nOutput:\n\n```\n{\n   \"message\":\"Successfully updated the saved query\",\n   \"status\":\"success\"\n}\n```\n\nThis example shows an error when the query sys\\_id and name are both missing from the method call.\n\n```\nvar queryJson = \"{\\\"type\\\":\\\"cmdb\\\",\\\"nodes\\\":[{\\\"label\\\":\\\"Server\\\",\\\"unique_id\\\":\\\"d93f96981b310210bccf42a3b24bcb41\\\",\\\"nodeType\\\":\\\"class\\\",\\\"image\\\":\\\"images/app.ngbsm/server.svg\\\",\\\"properties\\\":\\\"\\\",\\\"allowed_connections\\\":[],\\\"filters\\\":{\\\"platform\\\":\\\"cmdb_ci_server\\\",\\\"custom\\\":\\\"\\\"},\\\"ci_type\\\":\\\"cmdb_ci_server\\\",\\\"ci_type_label\\\":\\\"Server\\\",\\\"sys_id\\\":\\\"d93f96981b310210bccf42a3b24bcb41\\\",\\\"x\\\":72,\\\"y\\\":336,\\\"returnValues\\\":[],\\\"filters_attrib\\\":\\\"\\\",\\\"applied_filters\\\":\\\"\\\",\\\"isStartNode\\\":true,\\\"nodeId\\\":\\\"d93f96981b310210bccf42a3b24bcb41_4_23_2024_5_50_54\\\",\\\"name\\\":\\\"Server 1\\\",\\\"type\\\":\\\"class\\\",\\\"refFilterApplied\\\":false,\\\"focused\\\":false,\\\"id\\\":\\\"d93f96981b310210bccf42a3b24bcb41_4_23_2024_5_50_54\\\",\\\"className\\\":\\\"cmdb_ci_server\\\"},{\\\"label\\\":\\\"Web Server\\\",\\\"unique_id\\\":\\\"984f5a981b310210bccf42a3b24bcb03\\\",\\\"nodeType\\\":\\\"class\\\",\\\"image\\\":\\\"images/app.ngbsm/web_server.svg\\\",\\\"properties\\\":\\\"\\\",\\\"allowed_connections\\\":[],\\\"filters\\\":{\\\"platform\\\":\\\"cmdb_ci_web_server\\\",\\\"custom\\\":\\\"\\\"},\\\"ci_type\\\":\\\"cmdb_ci_web_server\\\",\\\"ci_type_label\\\":\\\"Web Server\\\",\\\"sys_id\\\":\\\"984f5a981b310210bccf42a3b24bcb03\\\",\\\"x\\\":446,\\\"y\\\":330,\\\"returnValues\\\":[],\\\"filters_attrib\\\":\\\"\\\",\\\"applied_filters\\\":\\\"\\\",\\\"isStartNode\\\":false,\\\"nodeId\\\":\\\"984f5a981b310210bccf42a3b24bcb03_4_23_2024_6_32_19\\\",\\\"name\\\":\\\"Web Server 1\\\",\\\"type\\\":\\\"class\\\",\\\"refFilterApplied\\\":false,\\\"focused\\\":false,\\\"id\\\":\\\"984f5a981b310210bccf42a3b24bcb03_4_23_2024_6_32_19\\\",\\\"className\\\":\\\"cmdb_ci_web_server\\\"}],\\\"edges\\\":[{\\\"id\\\":\\\"Server 1_Web Server 1\\\",\\\"from\\\":\\\"d93f96981b310210bccf42a3b24bcb41_4_23_2024_5_50_54\\\",\\\"to\\\":\\\"984f5a981b310210bccf42a3b24bcb03_4_23_2024_6_32_19\\\",\\\"isDotted\\\":false,\\\"type\\\":\\\"relation\\\",\\\"isReverse\\\":false,\\\"direction\\\":\\\"outbound\\\",\\\"hiddenLevel\\\":0,\\\"relations\\\":[\\\"607ad1b2c0a8010e01941856b365af90\\\"]}],\\\"usedNames\\\":{\\\"cmdb_ci_server\\\":1,\\\"cmdb_ci_database\\\":1,\\\"cmdb_ci_web_server\\\":1}}\";\n\nvar queryUpdate = SNC.CMDBQueryBuilderAPI.updateQuery('', '', queryJson);\n\ngs.info(JSON.stringify(JSON.parse(queryUpdate), null, 2));\n```\n\nOutput:\n\n```\n{\n   \"error\":\"INVALID_PARAM\",\n   \"message\":\"Invalid Parameters. Please provide either a valid sysId or a valid name of a saved query\"\n}\n```\n\n"}}