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

oharel
Kilo Sage

I have no idea why that is so, but what do you see in the logs? Maybe you have an error or a warning there.


LaurentChicoine
Tera Guru

Hi Zhen, you need to use the value behind the choice in your query:



In your case: addQuery('sys_class_name', 'cmdb_ci_appl')



To get the value behind the choice list, you can right click the choice field and click on Show choices.


Ahh Thank you! It worked!


what was finally corrected.. Can you please describe what was done to fix the issue.