How can we exclude any catalog item from recommended for you widget in Servicenow

Shreyas Khade
Giga Guru

Is there a way to exclude a particular catalog item from showing up on the recommended for you widget in the employee centre portal ? 

1 ACCEPTED SOLUTION

Shreyas Khade
Giga Guru

The code pasted below should ideally serve the purpose of just removing the catalog item from appearing on the portal.

Note: sn_hr_sp.ignoredCatalogs is a system property created that stores comma separated sys_ids of all those catalog items that are to be omitted from appearing on the portal.

 

(function() {
if (input && input.action == "loadData") {
var maxDisplayCount = 10;
data.instanceId = $sp.getDisplayValue("sys_id");
data.title = gs.getMessage(options.title);
data.userPredictionCount = options.user_prediction_count;
data.cardType = (options.list_type === 'Card List') ? options.card_behaviour + '' : '';
data.listType = (options.list_type === 'Card List') ? 'card-list' : 'simple-link';
var knowledgeBases = String($sp.getKnowledgeBases());

var displayCount = options.limit > maxDisplayCount ? maxDisplayCount : options.limit;
data.viewType = (displayCount > 3) ? 'max-view' : 'min-view';
var recentActivityCutoffInDays = options.recent_activity_cut_off_in_days;
var recentActivityCutoffDate = new GlideDateTime();
recentActivityCutoffDate.addDaysLocalTime(-recentActivityCutoffInDays);
var RelevantForYouUtil = new sn_hr_sp.RelevantForYouUtil();
var taxonomyId = $sp.getTaxonomies();
var catalogPayload = {
users: null,
catalogCount: displayCount,
ignoredCatalogs: 'Other Request',
recentActivityCutoffDate: recentActivityCutoffDate,
taxonomyId: taxonomyId
};
var articlesPayload = {
users: null,
knowledgeBases: knowledgeBases,
kbRecords : $sp.getAllKBRecords(knowledgeBases),
articleCount: displayCount,
recentActivityCutoffDate: recentActivityCutoffDate,
taxonomyId: taxonomyId
};

if (options.category === 'knowledge')
data.dataItems = RelevantForYouUtil.getRelevantArticlesAndCatalogs(articlesPayload, null, displayCount, data.userPredictionCount, taxonomyId);
else if (options.category === 'catalog')
data.dataItems = RelevantForYouUtil.getRelevantArticlesAndCatalogs(null, catalogPayload, displayCount, data.userPredictionCount, taxonomyId);
else
data.dataItems = RelevantForYouUtil.getRelevantArticlesAndCatalogs(articlesPayload, catalogPayload, displayCount, data.userPredictionCount, taxonomyId);

 

for(var i=0; i<data.dataItems.length;i++) {
var catIgnore = gs.getProperty('sn_hr_sp.ignoredCatalogs').split(',');
for (var j=0; j<catIgnore.length; j++)
{
if(data.dataItems[i].sys_id == catIgnore[j] ) {
data.dataItems.splice(i,1);
}
}
}

data.widgetsData = getWidgetsData(data.dataItems, data.listType);
}

function getWidgetsData(dataResults, listType) {
listType = (listType === 'card-list') ? 'card' : 'simple_link';
var dataPayload = [];
dataResults.forEach(function(article) {
var itemPayload = {};
var widgetName = article.category == 'catalog' ? 'catalog-content' : 'kb-content';
itemPayload.widgetTitle = data.title;
itemPayload.content = article.sys_id;
itemPayload.content_table = article.category == 'catalog' ? 'sc_cat_item' : 'kb_knowledge';
itemPayload.listType = listType;
itemPayload.widgetData = $sp.getWidget(widgetName, itemPayload);
dataPayload.push(itemPayload.widgetData);
});
return dataPayload;
}
})();

 

 

 

Please Mark the answer as helpful if it works 🙂

View solution in original post

6 REPLIES 6

Hi, how did you achieve this?  I tried adding to the same area of the Script that Sheryas Khade has highlighted but not working?  Did you place you code somewhere else in the 'Relevant for you' Server Script section or somewhere else?

hello @samera datta , 
this as per my understanding won't be recommended as this means doing customization to OOTB available table sc_cat_item by creation of a new field there. Moreover there is an additional database query with gliderecord in your script which shall increase execution time of the overall script.