Editing Recent and Popular items
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2024 02:29 AM
Hi i have a requirement to edit Recent and Popular items in service portal i want whatever item i select that should only be visible and it should be static i cloned the widget but not able to achieve the results.I'm pasting the OOB server side code if anyone can help me with the code change please help
(function() {
/* populate the 'data' object */
data.limit = options.limit || 8;
var recent_by = options.recent_by || 'view';
var recent = new GlideRecord('sp_log');
if (recent_by === 'view')
recent.addEncodedQuery('userDYNAMIC90d1921e5f510100a9ad2572f2b477fe^type=Cat Item View^sys_created_onONThis quarter@javascript:gs.beginningOfThisQuarter()@javascript:gs.endOfThisQuarter()');
else
recent.addEncodedQuery('userDYNAMIC90d1921e5f510100a9ad2572f2b477fe^type=Cat Item Request^sys_created_onONThis quarter@javascript:gs.beginningOfThisQuarter()@javascript:gs.endOfThisQuarter()');
recent.orderByDesc('sys_created_on');
recent.query();
var recentItems = [];
var catalogArr = ($sp.getCatalogs().value + "").split(",");
data.showPrices = $sp.showCatalogPrices();
while (recent.next() && recentItems.length < data.limit) {
if (isAlreadyAdded(recent.getValue('id')))
continue;
var catalogItemJS = new sn_sc.CatItem(recent.getValue('id'));
if (!catalogItemJS.canView(gs.isMobile()) || !catalogItemJS.isVisibleServicePortal())
continue;
var item = {};
var catItemDetails = catalogItemJS.getItemSummary(true);
if(!catItemDetails.visible_standalone)
continue;
var inCatalog = false;
for (var i=0; i<catItemDetails.catalogs.length; i++) {
if (catalogArr.indexOf(catItemDetails.catalogs[i].sys_id + "") >= 0) {
inCatalog = true;
break;
}
}
if (inCatalog) {
item.name = catItemDetails.name;
item.short_description = catItemDetails.short_description;
item.picture = catItemDetails.picture;
item.price = catItemDetails.price;
item.sys_id = catItemDetails.sys_id;
item.hasPrice = item.price != 0;
item.page = catItemDetails.type == 'order_guide'? 'sc_cat_item_guide' : 'sc_cat_item';
recentItems.push(item);
}
}
function isAlreadyAdded(catItemSysId) {
for (var i=0;i<recentItems.length;i++) {
if (catItemSysId==recentItems[i].sys_id)
return true;
}
return false;
}
data.recentItems = recentItems;
data.popularItems = getPopularItems();
function getPopularItems() {
return new SCPopularItems().useOptimisedQuery(gs.getProperty('glide.sc.portal.popular_items.optimize', true) + '' == 'true')
.baseQuery(options.popular_items_created + '')
.allowedItems($sp.getAllowedItems())
.visibleStandalone(true)
.visibleServicePortal(true)
.itemsLimit(options.limit || 8)
.restrictedItemTypes(['sc_cat_item_guide', 'sc_cat_item_wizard', 'sc_cat_item_content', 'sc_cat_item_producer'])
.itemValidator(function(item, itemDetails) {
if (!item.canView(gs.isMobile()) || !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();
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2024 02:38 AM
Popular is what is chosen the most and most recent is what has been chosen most recently. You can't make them static, that's the entire point of those. Why show static content? Just put your catalog there, without popular/recent and maybe just crate a category every one starts from and add the once you want to highlight there.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2024 02:42 AM
Thanks for replying mark but this is a business requirement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2024 02:49 AM
Business can tell you what they want, not how you deliver. If they want static content, just fill the first category the portal opens to with those items. That's what they want, right?
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark