Need help in scripting-Aggregate of all unique parent class with child for each type of relationshi
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2023 02:25 AM
Hi,
I want a report from the relationship table, cmdb_rel_ci that gives all the relationships group by parent class, child class and the relationship type with the relationship count.
For example- Parent Linux Server to Child VM Instance of the type Virtualized by::Virtualizes has 500 relationships
Parent ESX Server to Cjild IP Switch of the type IP Connection::IP Connection has 200 relationships
I have tried with the below code but it does not seem to be working
var aggCI = new GlideAggregate('cmdb_rel_ci');
aggCI.addEncodedQuery('child.operational_statusIN1,3,4,5,7,8');
aggCI.setLimit(10);
aggCI.groupBy('type');
aggCI.addAggregate('COUNT');
aggCI.query();
while(aggCI.next()){
gs.print('Parent class is '+aggCI.parent.sys_class_name.getDisplayValue()+' type is'+aggCI.type.getDisplayValue()+' '+aggCI.getAggregate('COUNT'));
var aggCI2=new GlideRecord('cmdb_rel_ci');
aggCI2.setLimit(2);
aggCI2.addQuery('type',aggCI.type);
aggCI2.groupBy('parent.sys_class_name');
aggCI2.addAggregate('COUNT');
aggCI2.query();
while(aggCI2.next()){
gs.print('Type is '+aggCI2.type.getDisplayValue()+' '+'Parent is '+aggCI2.parent.sys_class_name.getDisplayValue()+' Child is '+aggCI2.child.sys_class_name.getDisplayValue()+' Count is '+aggCI2.getAggregate('COUNT','type')+'and '+aggCI2.getAggregate('COUNT','child.sys_class_name'));
}
}
All this gives me is the count of each relationship type and parent/Child class name, not the count
0 REPLIES 0