- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2016 10:19 AM
Hello,
I am trying to get a count of the parent.sys_class_name in the cmdb_rel_ci table but I do not understand why the script is not working. I used this script previously to just pull sys_class_name from a different table and it had worked so I am not sure why parent.sys_class_name is not working.
Any ideas?
//count number of server instances grouped by sys class name
var agg = new GlideAggregate('cmdb_rel_ci');
agg.addAggregate('COUNT', 'parent.sys_class_name');
agg.groupBy('parent.sys_class_name');
agg.query();
while (agg.next()) {
var serverType = agg.parent.sys_class_name.getDisplayValue();
var hierarchy = new GlideRecord('u_land_o_lakes_physical_servers_allocation');
hierarchy.addQuery('u_allocate_to',serverType);
hierarchy.query();
var getCount = agg.getAggregate('COUNT', 'parent.sys_class_name');
if (hierarchy.next()) {
hierarchy.u_allocate_to = serverType;
hierarchy.update();
} else {
hierarchy.u_allocate_to = serverType;
hierarchy.insert();
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding