How to create a report to show CIs with no relationship?

Luiz Lucena
Mega Sage

Hello everyone, 

I need to create a report to show all CIs without a relationship to anything. 

Any idea what the query should look like?

Has anyone ever done anything like that?

Thanks,

11 REPLIES 11

Hi Akif, 

Sorry the late response!

Here is what I did (sorry, I'm very new in scripting).

Your script include should be something like this

function ciWithNoRelationships(){
    var cisWithNoRelationship = [];
    
    var ciGR = new GlideRecord("cmdb_ci");
    //ciGR.addEncodedQuery("sys_class_name!=cmdb_ci_endpoint_ajp^ORsys_class_name!=cmdb_ci_ad_controller");//Use this to exclude certain CI Classes
    ciGR.query();
    while(ciGR.next()){
        var relGR = new GlideRecord("cmdb_rel_ci");
        relGR.addEncodedQuery("parent="+ciGR.sys_id+"^ORchild="+ciGR.sys_id);
        relGR.query();
        if(relGR.getRowCount() == 0){
            cisWithNoRelationship.push(ciGR.sys_id.toString());
        }
    }
    
    return cisWithNoRelationship;
}

mikkojuola
Giga Guru

Hi Luiz,

If you'd like to accomplish this without scripting or creating a single new report, you might want to try Data Content Manager, a ServiceNow certified Built on Now app available in the ServiceNow Store.

If you just want to see how it work, you can book a 30-minute demo where I can demonstrate this exact use case.

Cheers,

--Mikko

 

EricDohr
ServiceNow Employee
ServiceNow Employee

CMDB Query Builder allows this logic.  From here you can create and schedule a report that will then become a data source.  You may want to break it down to specific use cases such as Business Applications with no relationships to Application Services.  Computers for example (personal) may not have a CI relationship.

Hi Eric, 

Looks like when migrated to this new community it lost the images.