The Now Platform® Washington DC release is live. Watch now!
A few weeks ago I was talking with one of our customers (I'll call him Joe) who had just finished writing a script that created a little report of how many items of each type were in his CMDB. Joe was quite happy with his script except that it took a long time to run. Here's what Joe had written:
var gr = new GlideRecord('cmdb_ci');
gr.orderBy('sys_class_name');
gr.query();
var name = '';
var count = 0;
while (gr.next()) {
var thisName = '' + gr.getValue('sys_class_name');
if (thisName == name)
count++;
else {
if (name != '')
gs.log(thisName + ': ' + count);
name = thisName;
count = 1;
}
}
gs.log(name + ': ' + count);
var ga = new GlideAggregate('cmdb_ci');
ga.addAggregate('COUNT', 'sys_class_name');
ga.query();
while(ga.next()) {
var result = ga.getAggregate('COUNT', 'sys_class_name');
gs.log(ga.getValue('sys_class_name') + ': ' + result);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.