Does anyone know how to get a list of incident or request categories that have not been used?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2017 12:05 PM
I can get a count of categories that have been used and how many times but I don't know how to get a list of categories that have not been used, does anyone know how to do this?
- Labels:
-
Reporting

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2017 01:44 PM
You can create a script include to:
- Query the choice table for the inc and req categories.
- Add those categories into an array.
- Next, perform a new query on the inc and req tables to find records that do not have any of those categories (something like "category", "NOT IN", "nameOfFirstArray"), you need to push these category sys_ids to a new array.
- Return the sys_ids of the category records from the last query.
- Save the script include.
- Next, go to Choice Lists.
- Add a condition where the Sys ID is javascript:nameOfScriptInclude().
- This should give you the list of categories that have not been used on an inc or req.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2017 02:30 PM
If its a one time check, maybe you can just do a group by on category in the incident / request list and compare it manually with the available choices.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2017 08:38 AM
too many categories for anything that requires a manual process.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2017 01:40 PM
Try this (background) script:
//Options
var onlyZero = 1 //set to 0 to display all categorie counts.
var table = 'incident';
//backgroundscript
var gr = new GlideRecord('sys_choice');
gr.addEncodedQuery("name="+ table +"^element=category^language=en^inactive=false");
gr.orderBy('value');
gr.query();
gs.print('Category|Count');
while (gr.next()) {
var count = new GlideAggregate('incident');
count.addQuery('category', gr.value);
count.addAggregate('COUNT');
count.query();
var catCount = 0;
if (count.next())
catCount = count.getAggregate('COUNT');
if (catCount == 0 || !onlyZero)
gs.print(gr.value + '|' + catCount);
}
It querys the choicelist for all active options, and does a glideaggregate for each choice.
If you want it as a report, I would create a databaseview, with this criteria, base on the sys_choices table, left joined to incident.
Then if you use the DB view and set a is empty filter on the number field, it will result in the unused categories