How to control Popular Items content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2022 06:27 AM
I’m seeing in other Community postings that you can control what shows up in the Service Portal "Popular Items" by cloning the SC Popular Items widget and adding script like I’ve done in the below screenshot. This is not getting me the desired results and does appear to be removing any of the catalog items I need removed from Popular Items. If I right-click/Ctrl on Popular Items in the Service Portal and select Instance in Page Editor, the widget it is using is SC Category Page. So, should I actually be cloning the SC Category Page widget and adding my script to that? If so, where? I don’t see anywhere its Server Script that it is doing any count.AddQuery. Thanks.
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2022 06:35 AM
Hi Sulabh,
The script I provided is from the OOB SC Category Page widget on NOT my cloned version I've been playing around with, so it has not been edited. Yes, it may be the difference between Rome and San Diego. Any suggestions on updating our San Diego version to add a count.addQuery lines to control Popular Items content would be helpful.
In the meantime, I have changed the below section of script in the SC Category Page server script from this.......
data.show_more = false;
if (GlideStringUtil.nil(data.category_id)) {
data.items = getPopularItems();
data.show_popular_item = true;
data.all_catalog_msg = (($sp.getCatalogs().value + "").split(",")).length > 1 ? gs.getMessage("All Catalogs") : "";
data.all_cat_msg = gs.getMessage("All Categories");
data.category = {title: gs.getMessage("Popular Items"),
description: ''};
return;
}
to this, to hide the Popular Items.
data.show_more = false;
if (GlideStringUtil.nil(data.category_id)) {
return;
}
So now it defaults to this when no category is selected.
Ultimately, I would like to put Popular Items back, but NOT have it showing any catalog items that are under the "IT ONLY" category. Any suggestions on how to accomplish this would be appreciated.
Thanks,
Chris

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2022 07:26 AM
You can try this function inside server script, Here you can mention your conditions to restrict the popular items.
function queryItems(catalog, categoryId, startWindow, endWindow) {
var scRecord = new sn_sc.CatalogSearch().search(catalog, categoryId, '', false, options.show_items_from_child != 'true');
scRecord.addQuery('sys_class_name', 'NOT IN', 'sc_cat_item_wizard');
scRecord.addEncodedQuery('hide_sp=false^ORhide_spISEMPTY^visible_standalone=true');
scRecord.chooseWindow(startWindow, endWindow);
scRecord.orderBy('order');
scRecord.orderBy('name');
scRecord.query();
return scRecord;
}
Regards
Sulabh Garg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2022 05:50 AM
Hi Sulabh,
I've tried coding this several different ways. See the three // lines below for what I've tried. None of these worked by filtering out catalog items where the category was IT Only. Open to suggestions. Thanks!
function queryItems(catalog, categoryId, startWindow, endWindow) {
var scRecord = new sn_sc.CatalogSearch().search(catalog, categoryId, '', false, options.show_items_from_child != 'true');
scRecord.addQuery('sys_class_name', 'NOT IN', 'sc_cat_item_wizard');
scRecord.addEncodedQuery('hide_sp=false^ORhide_spISEMPTY^visible_standalone=true');
//scRecord.addEncodedQuery('category!=fd4980572bc78d002f5e8740f8da1502');
//scRecord.addEncodedQuery('cat_item.category!=fd4980572bc78d002f5e8740f8da1502');
//scRecord.addEncodedQuery('cat_item.categoryNOT LIKEIT ONLY');
scRecord.chooseWindow(startWindow, endWindow);
scRecord.orderBy('order');
scRecord.orderBy('name');
scRecord.query();
return scRecord;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2022 10:19 PM
I had a similar issue in the San Diego version. I have replaced getPopularItems()
function with the old Rome version. Doing this my issue was resolved.