Unused catalog items

PHOTO EMBED

Thu Nov 04 2021 07:57:47 GMT+0000 (UTC)

Saved by @mathiasVDD #javascript

getUnusedCatalogueItems: function (unusedDuration)
       {
		   var encQuery = 'sys_created_onRELATIVEGE@month@ago@'+ unusedDuration +'^cat_itemISNOTEMPTY';
		   var cat_items = [];
		   var results = [];
		   var grAggServReq = new GlideAggregate ('sc_req_item');
		   grAggServReq.groupBy('cat_item');
		   grAggServReq.addEncodedQuery(encQuery);
		   grAggServReq.query();
		   while (grAggServReq.next()){
			   cat_items.push(grAggServReq.getValue('cat_item').toString());
		   }
		   var grUnusedCatItems = new GlideRecord ('sc_cat_item');
		   grUnusedCatItems.addActiveQuery();
		   grUnusedCatItems.addQuery('sys_id', 'NOT IN', cat_items);
		grUnusedCatItems.addEncodedQuery('type!=bundle^sys_class_name!=sc_cat_item_guide^type!=package^sys_class_name!=sc_cat_item_content^active=true');
		   grUnusedCatItems.query();
		   while(grUnusedCatItems.next()){
			   results.push(grUnusedCatItems.getValue('sys_id').toString());
		   }
		   
           return results;

       },
content_copyCOPY