Get unique parent categories (service catalog categories) - GlideAggregate - and grab their subcategories
var ga= new GlideAggregate('sc_category');
ga.addAggregate('COUNT', 'parent');
ga.addQuery('sc_catalog','9f6ef0cddb028f80edfc7cbdae96191c');
ga.addNotNullQuery('parent');
ga.addHaving('COUNT', '>', 0);
ga.query();
var dupls=[];
var parentCats=[];
dupls.push("The following " + ga.getRowCount() + " records are duplicate on parent");
while (ga.next()) {
var DuplLine=ga.getAggregate('COUNT', 'parent') + " => " + ga.getElement('parent.title');
dupls.push(DuplLine);
//gs.print(DuplLine);
parentCats.push(ga.getElement('parent.title') );
}
var output=parentCats.toString();
output=output.replaceAll(",","\n");
gs.print(output);
output:
*** Script: Hardware
Software
Devices
Accessories
Storage
Servers
Technical
Telephony
for the subcategories:
parentCats.forEach(myFunction); function myFunction(item, index) { //gs.print( index + ":" + item.title); //gs.print( index + ":" + item.sys_id); gs.print('NEXT CATEGORY BATCH: ************' + item.title); var grCats= new GlideRecord('sc_category'); grCats.addQuery('parent', item.sys_id); grCats.query(); while (grCats.next()){ gs.print(grCats.title); } }
Comments
Post a Comment