SC Category Page (Popular items) must populate only record producers and not service catalogs

Preethika Wagle
Tera Contributor

OOTB SC Category Page shows the list of popular items . Right now it displays only service catalogs . I need to display ONLY record producers . it should either take sc_cat_item_producer table only or it can add condition for sc_cat_item (sc_catalogs = incident ,wherein it is a reference field) . I tried with different possible approach . 

By also changing 

.restrictedItemTypes('sc_cat_item_guide,sc_cat_item_wizard,sc_cat_item_content,sc_cat_item_producer'.split(','))

as 

.restrictedItemTypes('sc_cat_item_producer'.split(','))

 

PreethikaWagle_0-1716264438104.png

 

function getPopularItems() {
        return new SCPopularItems().useOptimisedQuery(gs.getProperty('glide.sc.portal.popular_items.optimize', true) + '' == 'true')
            .baseQuery(options.popular_items_created + '')
            .allowedItems(getAllowedCatalogItems())
            .visibleStandalone(true)
            .visibleServicePortal(true)
            .itemsLimit(6)
            .restrictedItemTypes('sc_cat_item_guide,sc_cat_item_wizard,sc_cat_item_content,sc_cat_item_producer'.split(','))
            .itemValidator(function(item, itemDetails) {
                if (!item.canView() || !item.isVisibleServicePortal())
                    return false;
 
                return true;
            })
            .responseObjectFormatter(function(item, itemType, itemCount) {
                return {
                    order: 0 - itemCount,
                    name: item.name,
                    short_description: item.short_description,
                    picture: item.picture,
                    price: item.price,
                    sys_id: item.sys_id,
                    hasPrice: item.price != 0,
                    page: itemType == 'sc_cat_item_guide' ? 'sc_cat_item_guide' : 'sc_cat_item'
                };
            })
            .generate();
    }
 
function getAllowedCatalogItems () {
var allowedItems = [];
catalogIDArr.forEach(function(catalogID) {
var catalogObj = new sn_sc.Catalog(catalogID);
var catItemIds = catalogObj.getCatalogItemIds();
for(var i=0; i<catItemIds.length; i++) {
if (!allowedItems.includes(catItemIds[i]))
allowedItems.push(catItemIds[i]);
}
});
return allowedItems;
}

 

2 REPLIES 2

VarunS
Kilo Sage

@Preethika Wagle 

Try the below script.

 

function getPopularItems() {
    return new SCPopularItems()
        .useOptimisedQuery(gs.getProperty('glide.sc.portal.popular_items.optimize', true) + '' == 'true')
        .baseQuery(options.popular_items_created + '')
        .allowedItems(getAllowedCatalogItems())
        .visibleStandalone(true)
        .visibleServicePortal(true)
        .itemsLimit(6)
        .restrictedItemTypes('sc_cat_item_producer'.split(','))
        .itemValidator(function(item, itemDetails) {
            if (!item.canView() || !item.isVisibleServicePortal())
                return false;

            return true;
        })
        .responseObjectFormatter(function(item, itemType, itemCount) {
            return {
                order: 0 - itemCount,
                name: item.name,
                short_description: item.short_description,
                picture: item.picture,
                price: item.price,
                sys_id: item.sys_id,
                hasPrice: item.price != 0,
                page: 'sc_cat_item_producer'
            };
        })
        .generate();
}

function getAllowedCatalogItems() {
    var allowedItems = [];
    catalogIDArr.forEach(function(catalogID) {
        var catalogObj = new sn_sc.Catalog(catalogID);
        var catItemIds = catalogObj.getCatalogItemIds();
        for (var i = 0; i < catItemIds.length; i++) {
            var catItem = new GlideRecord('sc_cat_item_producer');
            if (catItem.get(catItemIds[i]) && catItem.getValue('sys_class_name') == 'sc_cat_item_producer') {
                if (!allowedItems.includes(catItemIds[i])) {
                    allowedItems.push(catItemIds[i]);
                }
            }
        }
    });
    return allowedItems;
}

 

 

1. Restricted Item Types:

•The restrictedItemTypes method is updated to only include 'sc_cat_item_producer'. This ensures that only record producers are considered.

2. Allowed Items Function:

•The getAllowedCatalogItems function now checks if each catalog item is of type sc_cat_item_producer before adding it to the allowed items array.

3. Response Object Formatter:

•The page property in the formatter is set to 'sc_cat_item_producer' to ensure correct routing.

@VarunS  Thanks for the response. However this isn't working , somewhere the record producers are getting restricted .The results shows no items to show

 

Tried with system properties to exclude the items ,it works for service catalog .but doesn't work for Record Producers