Does anyone know how to get a list of incident or request categories that have not been used?

trdaniels
Tera Expert

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?

8 REPLIES 8

Output from the background script:



category_count-2017-03-20_8-10-17.png


ok, seem good doesnt it?


if you want to see all category counts change set   variable onlyZero = 0



if you dont want the lines in between push the values to an array an print it in the last line



If its ok, please mark as answered...



//Options  


var onlyZero = 0 //set to 0 to display all categorie counts.  


var table = 'incident';  


 


//backgroundscript  


var gr = new GlideRecord('sys_choice');  


var output = [];


output.push('Category|Count');


gr.addEncodedQuery("name="+ table +"^element=category^language=en^inactive=false");  


gr.orderBy('value');  


gr.query();  


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)  


    output.push(gr.value + '|' + catCount);  


}  


gs.print('\n' + output.join('\n'));


Hi Arnoud,



Thank you for your time. The two categories in the script output have been used thousands of times or am I reading it wrong? Some of our categories have 4 levels, a parent and 4 subcategories does that matter?



Example: Hardware > Telephony > Cisco > PBX > Failure


Arnoud Kooi
ServiceNow Employee
ServiceNow Employee

I don't know the structure and quantity of your data. Good luck.