Popular Items to be displayed based on selection

Archana Singh2
Tera Expert

Hi All,

I have this req: "I would like to be able to determine what catalog items are shown under popular items to ensure that users can easily find what they need."

I have done below on "SC Category Page" widget by creating its clone.

1) Below HTML added. 

<div ng-if="data.show_popular_item == true">
<div class="row">
<div class="col-xs-4">
<label for="Catalog Item">${Catalog Item}
<i class="fa fa-info-circle" uib-tooltip="${SRM and Catalogue Product Owner can identify the Items to be displayed as popular items}" tooltip-placement="right" tooltip-append-to-body="true"></i>
</label>
<sn-record-picker id="Catalog Item"
field="catalogitem"
table="'sc_cat_item'"
display-field="'name'"
value-field="'sys_id'"
search-fields="'name'"
default-query="'active=true'"
page-size="100">
</sn-record-picker>
</div>
</div>
</div>

After this: 

<div ng-init="spSearch.targetCatalog()">

Below Client Script Added.

$scope.$on("field.change", function(evt, parms) {

$scope.data.setCatalogItem = parms.newValue;

$scope.server.update().then(function(response) {

spUtil.update($scope);

})

});

After this: 

$scope.startItemList = function() {
$scope.stopLoader = true;
}

Below Server Script Added.

if(input.setCatalogItem){
data.setCatalogItem = input.setCatalogItem;
var catitem = new GlideAggregate('sc_cat_item');
catitem.addQuery('sys_id',data.setCatalogItem);
catitem.query();

while (catitem.next()) {

if (!$sp.canReadRecord("sc_cat_item", catitem.sys_id))

continue; // user does not have permission to see this item

var item = {};


item.name = catitem.name.getValue();


item.short_description = catitem.short_description.getValue();


item.picture = catitem.picture.getDisplayValue();


item.price = catitem.price.getValue();


item.sys_id = catitem.sys_id.getDisplayValue();
item.page = 'sc_cat_item';
items.push(item);
}
}

After this: 

function getPopularItems () {
var limit = 6;
var items = [];
var allowedItems = getAllowedCatalogItems();

Based on Catalog Item selection, the selected Catalog Item is appearing in Popular Items but as soon as page is refreshing. It's disappearing, i have tried a lot but no luck.

Any help would be highly appreciated.

In an attachment i have attached the screen shot. 

Thank You.

1 ACCEPTED SOLUTION

Archana Singh2
Tera Expert

Hi All,

This is fixed. So the solution taken as below:

1) 'Enable Popular Item' as true/false type -> field created on 'sc_cat_item' as this configuration should be done by those who has 'Catalog' role.

2) Based on the configuration - the popular item would be displayed under the Popular Items section.

In order to achieve this just added below Server Script - 

var catitem = new GlideAggregate('sc_cat_item');
catitem.addQuery('sc_catalogs', $sp.getCatalogs().value);
catitem.addQuery('u_enable_popular_item',true);
catitem.query();

while (catitem.next()) {

if (!$sp.canReadRecord("sc_cat_item", catitem.sys_id))

continue; // user does not have permission to see this item

var item = {};


item.name = catitem.name.getValue();


item.short_description = catitem.short_description.getValue();


item.picture = catitem.picture.getDisplayValue();


//item.price = catitem.price.getValue();


item.sys_id = catitem.sys_id.getDisplayValue();
var itemcount = 0;
var OrderGuide = new GlideRecord('sc_cat_item_guide');
OrderGuide.addQuery('sys_id', item.sys_id);
OrderGuide.query();
while (OrderGuide.next()){
item.page = 'sc_cat_item_guide';
itemcount = itemcount+1;
}
var CatalogItem = new GlideRecord('sc_cat_item');
CatalogItem.addQuery('sys_id', item.sys_id);
CatalogItem.query();
while (CatalogItem.next()){
if(itemcount == 0)
item.page = 'sc_cat_item';
}
items.push(item);
}

and commented below OOTB Server Script as Customer dose not want to show based on frequent submitted RITM which is doing by OOTB.

/* var count = new GlideAggregate('sc_req_item');
count.addAggregate('COUNT','cat_item');
count.groupBy('cat_item.sys_id');
count.addQuery('cat_item.sys_class_name', 'NOT IN', 'sc_cat_item_guide,sc_cat_item_wizard,sc_cat_item_content,sc_cat_item_producer');
count.addQuery('cat_item', "IN", allowedItems);
count.addQuery('cat_item.visible_standalone','true');
count.addEncodedQuery(createdQuery + 'cat_item.hide_sp=false^ORcat_item.hide_spISEMPTY');
count.orderByAggregate('COUNT', 'cat_item');
count.query();
while (count.next() && items.length < limit) {
var catalogItemJS = new sn_sc.CatItem(count.getValue("cat_item.sys_id"));
if (!catalogItemJS.canView() || !catalogItemJS.isVisibleServicePortal())
continue;
var item = {};
var catItemDetails = catalogItemJS.getItemSummary();

item.order = 0 - count.getAggregate('COUNT', 'cat_item');
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 = 'sc_cat_item';
items.push(item);
}*/

Now this is working as expected now.

Thank You.

View solution in original post

6 REPLIES 6

Yes, Thank you so much!!

Hi smfoister,

The above is Server script which is added in clone Widget of SC Category Page Widget.

Thank You.
 
smfoister
Solutions Architect at Hillsborough County Government, Florida
Helpful Answers 5
Knowledge 20 Registrant
SNUG Member
145 points