How to do addQuery on a choice field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2016 02:36 PM
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?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2016 01:55 AM
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.