- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2018 09:15 AM
Hi,
I want to display the top 3 catalog items based on the volume of tickets raised.
Please help!!
Thanks,
Gopi
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2018 12:50 PM
Background script? You can do something like this:
var limit = 3;
var items = [];
var count = new GlideAggregate('sc_req_item');
count.addAggregate('COUNT','cat_item');
count.groupBy('cat_item');
count.addQuery('cat_item.sys_class_name', 'NOT IN', 'sc_cat_item_guide,sc_cat_item_wizard,sc_cat_item_content');
count.orderByAggregate('COUNT', 'cat_item');
count.query();
while (count.next() && items.length < limit) {
var item = {};
item.count = count.getAggregate('COUNT', 'cat_item');
item.name = count.cat_item.name.getDisplayValue();
item.short_description = count.cat_item.short_description.getDisplayValue();
item.picture = count.cat_item.picture.getDisplayValue();
item.price = count.cat_item.price.getDisplayValue();
item.hasPrice = count.cat_item.price != 0;
item.sys_id = count.cat_item.sys_id.getDisplayValue();
items.push(item);
}
for (var i = 0; i < items.length; i++) {
var line = items[i];
gs.print(line.name);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2018 09:20 AM
Report on requested item table, group by item, where State is closed. That should give you a count for each catalog item so you can determine which ones as the highest volume.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2018 09:22 AM
If you need a quick and dirty answer, try this:
Add the Item field to a list view and filter the list as desired.
Right-click the Item header and choose Bar Chart.
The largest bar on the left is the highest count.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2018 10:28 AM
Hi,
Yes I have tried all these. But what i need is to display the first 3 items with highest number of tickets raised.
How can i achieve this through scripting ?
Thanks,
Gopi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2018 12:50 PM
Background script? You can do something like this:
var limit = 3;
var items = [];
var count = new GlideAggregate('sc_req_item');
count.addAggregate('COUNT','cat_item');
count.groupBy('cat_item');
count.addQuery('cat_item.sys_class_name', 'NOT IN', 'sc_cat_item_guide,sc_cat_item_wizard,sc_cat_item_content');
count.orderByAggregate('COUNT', 'cat_item');
count.query();
while (count.next() && items.length < limit) {
var item = {};
item.count = count.getAggregate('COUNT', 'cat_item');
item.name = count.cat_item.name.getDisplayValue();
item.short_description = count.cat_item.short_description.getDisplayValue();
item.picture = count.cat_item.picture.getDisplayValue();
item.price = count.cat_item.price.getDisplayValue();
item.hasPrice = count.cat_item.price != 0;
item.sys_id = count.cat_item.sys_id.getDisplayValue();
items.push(item);
}
for (var i = 0; i < items.length; i++) {
var line = items[i];
gs.print(line.name);
}