Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Shreyas Khade
Tera 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
Tera 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

5 REPLIES 5

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?