- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2018 11:08 AM
I am trying to find out the number of childs that exist to a parent by gliding the relationship table, I am using the below script but result coming as 'undefined'.
var ciSysIds = ['09653fa7db4f9b00e0a45bc0cf96192c'];
var agg1 = new GlideRecord('cmdb_rel_ci');
agg1.addAggregate('count');
agg1.addQuery('parent','IN',ciSysIds);
agg1.addQuery('type.parent_descriptor','members');
agg1.addQuery('type.child_descriptor','member of');
agg1.groupBy('child');
agg1.query();
if(agg1.next()) {
var count = agg1.getAggregate('count');
gs.info(count);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2018 05:30 AM
parentSysIds = agg.getValue('parent');
var agg1 = new GlideAggregate('cmdb_rel_ci');
agg1.addAggregate('count');
agg1.addQuery('parent','IN',parentSysIds);
agg1.addQuery('type.parent_descriptor','members');
agg1.addQuery('type.child_descriptor','member of');
agg1.groupBy('parent');
agg1.query();
if(agg1.next()) {
var count = agg1.getAggregate('count');
gs.info(count);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2018 11:49 AM
Thanks for the reply Pradeep. You suggestion was working but I am only seeing count as 1 when there are 5 childs to the CI that I am gliding for. Any thoughts?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2018 11:52 AM
Thanks for the update, Ryan. Replace if with while loop in your script and check once.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2018 11:55 AM
It's working after changing IF to While but I am seeing individual counts instead of number. Thanks!
*** Script: 1
*** Script: 1
*** Script: 1
*** Script: 1
*** Script: 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2018 05:30 AM
parentSysIds = agg.getValue('parent');
var agg1 = new GlideAggregate('cmdb_rel_ci');
agg1.addAggregate('count');
agg1.addQuery('parent','IN',parentSysIds);
agg1.addQuery('type.parent_descriptor','members');
agg1.addQuery('type.child_descriptor','member of');
agg1.groupBy('parent');
agg1.query();
if(agg1.next()) {
var count = agg1.getAggregate('count');
gs.info(count);
}