Bulk create CMDB Query Builder

garyminnick
Tera Contributor

I need to create 100+ Dynamic CI's and we are using an approach given to us by ServiceNow support.  This involves creating a CMDB Query Builder, then create a CMDB Group that uses the CMDB Query Builder, and then create a Dynamic CI using the CMDB group.  Scripting the CMDB Group and Dynamic CI should be easy, but I am not sure if that is possible with CMDB Query Builder.   The CMDB Query Builder will have the same 2 tables and filters, just different text for the search.

The table that holds these queries, qb_saved_query, does seem to have a common format and is very similar for these that are the same format, but occasionally I will see "$$hashKey":"object:3343" in the query and then it will disappear, and I am not sure what that is for or what triggers it.  If not for that I think it would be easy to script this.

 

Thanks!!!

5 REPLIES 5

I just tested it out and it works just fine.

 

I manually created a CMDB Query Builder using my example criteria. The output was 3 expected CIs.

 

I opened the CMDB Query Builder record in Saved Queries [qb_saved_query] and copied the JSON. I updated the JSON to include the escape character for the double quotes, and used the example code from CMDBQueryBuilderAPI.

 

It created the same query, and we can alter the JSON to use different values for the criteria for different queries.