Export category and subcategory

sbolton
Mega Expert

Is there a way to export out the category and subcategory combinations into an excel file?   for example

Category   : Access       - Sub category: A, B, C

Category : Hardware   - Sub Category: D, E , F

Access   |     A

Access   |   B

Access     |   C

Hardware     |   D

Hardware   |     E

hardware     |   F

3 REPLIES 3

Deepak Ingale1
Mega Sage

https://myinstance.service-now.com/sys_choice.do?CSV&sysparm_default_export_fields=all


Run this in the address tab of browser. It will give you all the choice records.


You can then sort them with dependent value


bernyalvarado
Mega Sage

Hi Sean, the following script should be able to do that for you.



var catChoice = new GlideRecord('sys_choice');


catChoice.addQuery('element','category');


catChoice.query();


while (catChoice.next()){


      var subCats = [];


      var subCatChoice = new GlideRecord('sys_choice');


      subCatChoice.addQuery('dependent_value', catChoice.value);


      catChoice.addQuery('element','subcategory');


      subCatChoice.query();


      while(subCatChoice.next()){


          subCats.push(subCatChoice.value.toString());


      }


      gs.print (catChoice.value + '|' + subCats.join(','));


}



You can execute it from a background script. Just make sure you have security_admin role and that you have elevated your privileges.



I hope it is helpful!



Thanks,


Berny


Stephen H_
Tera Contributor

I found the following to be easier without needing to use a script.

Just open the Choices table as a list (sys_choice.list). Then I just filtered "Element" by "subcategory".

Doing it this way also allows you to use regular filter options and then exporting to Excel/CSV by right-clicking on the column names. 

 

find_real_file.png