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-01-2016 02:52 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2016 03:52 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2016 03:54 PM
Ahh Thank you! It worked!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2016 01:29 AM
what was finally corrected.. Can you please describe what was done to fix the issue.