Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How do I pull the parent.sys_class_name in a query?

zsquared
Tera Contributor

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();

  }

}

1 ACCEPTED SOLUTION

bernyalvarado
Mega Sage

Hi Zhen,



On line 9, try the following instead:



var serverType = agg.getValue('parent.sys_class_name');



Thanks,


Berny


View solution in original post

3 REPLIES 3

bernyalvarado
Mega Sage

Hi Zhen,



On line 9, try the following instead:



var serverType = agg.getValue('parent.sys_class_name');



Thanks,


Berny


Thank you! I also realized it was an error in my syntax!


bernyalvarado
Mega Sage

I have tried it and it works .



Hope it helps!



Thanks,


Berny