How to do addQuery on a choice field?

zsquared
Tera Contributor

Hi everyone,

I am trying to run a business script but for some reason, if I add an addQuery to the script, the script no longer runs--see line 2.

var agg = new GlideAggregate('cmdb_ci_appl');

agg.addQuery('sys_class_name', 'Application');

agg.addAggregate('COUNT', 'name');

agg.query();

while (agg.next()) {

  var appName = agg.name.getDisplayValue();

  var hierarchy = new GlideRecord('u_lol_applications');

  hierarchy.addQuery('u_application_name',appName);

  hierarchy.query();

  if (hierarchy.next()) {

  hierarchy.u_application_name = appName;

  hierarchy.update();

  } else {

  hierarchy.initialize();

  hierarchy.u_application_name = appName;

  hierarchy.insert();

  }

}

I believe it is because the field name has choices.   Any ideas on how to query a field that has choices?

5 REPLIES 5

Hi Paramahanns Rathnakumar,



Instead of   Table label, name needs to used i.e. 'cmdb_ci_appl'



var agg = new GlideAggregate('cmdb_ci_appl');


agg.addQuery('sys_class_name', 'Application');     // Instead of   Table label, name needs to used i.e. 'cmdb_ci_appl'


agg.addAggregate('COUNT', 'name');


agg.query();



Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.