sc-category widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2022 01:53 AM
Hello,
i have an issue with in my sc_category page on our service portal.
in this page i have 2 widget SC Categories and a custom one New SC Category Page who is a clone of SC Category Page widget
when I click on a category of the widget SC Categories the items of the category are not displayed and I don't know why
I think the problem comes from the client script of the widget New SC Category Page
function ($scope, spUtil, $rootScope, $location, $timeout, $window) {
$scope.hideItemWidget = !$scope.data.category_id;
if ($scope.data.category) {
if (!$scope.data.categories)
$scope.data.categories = [];
$scope.data.categories.unshift({label: $scope.data.sc_catalog || $scope.page.title, url: '?id=' + $scope.data.sc_catalog_page });
if ($scope.data.show_popular_item)
$scope.data.categories.push({label: $scope.data.all_cat_msg, url: '#'});
else
$scope.data.categories.push({label: $scope.data.category.title, url: '#'});
$timeout(function() {
$rootScope.$broadcast('sp.update.breadcrumbs', $scope.data.categories);
});
spUtil.setSearchPage('sc');
}
$scope.showCategories = function() {
$scope.hideItemWidget = true;
$rootScope.$broadcast("$sp.service_catelog.show.categories_widget");
}
var listenerForCatItems = $scope.$on("$sp.service_catelog.show.items_widget", function() {
$scope.hideItemWidget = false;
});
/*=============== Begin link handling ===============*/
$scope.changeView = function (view) {
spUtil.setPreference('catalog-item-list-view', view)
$scope.view = view;
}
spUtil.getPreference('catalog-item-list-view', function(value) {
$scope.view = value || 'card';
});
$scope.isTouchDevice = function(){
return ('ontouchstart' in $window);
}
$scope.loadMore = function (){
$scope.data.new_limit = $scope.data.limit + ($scope.options.limit_item || 9);
$scope.stopLoader = false;
$scope.server.update().then(function (){
$scope.data.limit = $scope.data.new_limit;
$scope.stopLoader = true;
})
}
$scope.onClick = function($event, item) {
var lp = getLinkParts(item);
if (typeof lp == "string")
return; // can't intercept/redirect external content item
$event.stopPropagation();
$event.preventDefault();
var evt = {item: item, search: lp};
// This will let a wrapper widget intercept and redirect somewhere else
$scope.$emit($scope.options.click_event_name, evt);
};
function getLinkParts(item) {
if (item.sys_class_name == 'sc_cat_item_content' && item.content_type == 'external')
return item.url;
return {id: item.page, sys_id: item.sys_id, sysparm_category: $scope.data.category_id};
}
$scope.getItemHREF = function(item) {
var lp = getLinkParts(item);
if (typeof lp == "string")
return lp;
return "?id=" + lp.id + "&sys_id=" + lp.sys_id + "&sysparm_category=" + $scope.data.category_id;
}
var unregister = $rootScope.$on($scope.options.click_event_name, function($event, o) {
if ("url" in o)
$location.href = o.url;
else
$location.search(o.search);
});
var mlq;
if ($window.matchMedia) {
mql = $window.matchMedia('screen and (max-width: 768px)');
mql.addListener(handleMatchMedia);
handleMatchMedia(mql);
}
function handleMatchMedia(mlq) {
if (!mql.matches) {
spUtil.getPreference('catalog-item-list-view', function(value) {
$scope.view = value || 'card';
$scope.isMobile = false;
});
}
else {
$timeout(function() {
$scope.view = 'card';
$scope.isMobile = true;
})
}
}
$scope.$on("$destroy", function() {
unregister();
listenerForCatItems();
if (mql)
mql.removeListener(handleMatchMedia);
});
$scope.startItemList = function() {
$scope.stopLoader = true;
}
/*=============== End link handling ===============*/
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2022 05:21 AM
Hi
Regards,
Vamsi S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2022 11:04 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2022 02:33 AM
here is the server code if it can help
(function() {
data.category_id = $sp.getParameter("sys_id");
if (options && options.sys_id)
data.category_id = options.sys_id;
data.showPrices = $sp.showCatalogPrices();
data.sc_catalog_page = $sp.getDisplayValue("sc_catalog_page") || "sc_home";
data.sc_category_page = $sp.getDisplayValue("sc_category_page") || "sc_category";
data.sc_catalog = $sp.getDisplayValue("sc_catalog");
var not_included = 0;
if (GlideStringUtil.nil(data.category_id)) {
data.items = getPopularItems();
data.show_popular_item = true;
data.all_cat_msg = gs.getMessage("All Categories");
data.category = {title: gs.getMessage("Popular Items"),
description: ''};
return;
}
data.show_popular_item = false;
// Does user have permission to see this category?
var categoryId = '' + data.category_id;
var categoryJS = new sn_sc.CatCategory(categoryId);
if (!categoryJS.canView()) {
data.error = gs.getMessage("You do not have permission to see this category");
return;
}
data.category = {title: categoryJS.getTitle(),
description: categoryJS.getDescription()};
var catalog = $sp.getValue('sc_catalog');
var scRecord = new sn_sc.CatalogSearch().search(catalog, categoryId, '', false, options.show_items_from_child != 'true');
scRecord.addQuery('sys_class_name', 'NOT IN', 'sc_cat_item_wizard');
scRecord.addEncodedQuery('hide_sp=false^ORhide_spISEMPTY');
scRecord.orderBy('order');
scRecord.orderBy('name');
scRecord.query();
var items = data.items = [];
var count = 1;
data.limit = 9;
if (input && input.new_limit)
data.limit = input.new_limit;
else if (options.limit_item)
data.limit = options.limit_item;
while (scRecord.next() && count <= data.limit) {
var catalogItemJS = new sn_sc.CatItem(scRecord.getUniqueValue());
if (!catalogItemJS.canView() || !catalogItemJS.isVisibleServicePortal()) {
not_included += 1;
continue;
}
var catItemDetails = catalogItemJS.getItemSummary();
var 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 = catItemDetails.show_price;
item.page = 'sc_cat_item';
item.type = catItemDetails.type;
item.order = catItemDetails.order;
item.sys_class_name = catItemDetails.sys_class_name;
if (item.type == 'order_guide') {
item.page = 'sc_cat_item_guide';
} else if (item.type == 'content_item') {
item.content_type = catItemDetails.content_type;
item.url = catItemDetails.url;
if (item.content_type == 'kb') {
item.kb_article = catItemDetails.kb_article;
item.page = 'kb_article';
item.sys_id = item.kb_article;
} else if (item.content_type == 'external') {
item.target = '_blank';
}
}
items.push(item);
count ++;
}
data.total_item = scRecord.getRowCount() - not_included + '';
data.more_msg = gs.getMessage("{0} of {1}", [data.limit, data.total_item]);
data.categories = [];
while(categoryJS && categoryJS.getParent()) {
var parentId = categoryJS.getParent();
categoryJS = new sn_sc.CatCategory(parentId);
var category = {
label: categoryJS.getTitle(),
url: '?id='+data.sc_category_page+'&sys_id=' + parentId
};
data.categories.unshift(category);
}
function getPopularItems () {
var catalog = $sp.getValue('sc_catalog');
var limit = 6;
var items = [];
var count = new GlideAggregate('sc_req_item');
count.addAggregate('COUNT','cat_item');
count.groupBy('cat_item');
count.addQuery('cat_item.sys_class_name', 'NOT IN', 'sc_cat_item_guide,sc_cat_item_wizard,sc_cat_item_content');
count.addQuery('cat_item.sc_catalogs', 'IN', catalog);
count.addEncodedQuery('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.cat_item.sys_id.getValue());
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);
}
var producers = 0;
count = new GlideAggregate('sc_item_produced_record');
count.addQuery('producer.sc_catalogs', 'IN', catalog);
count.addEncodedQuery('producer.hide_sp=false^ORproducer.hide_spISEMPTY');
count.addAggregate('COUNT', 'producer');
count.groupBy('producer');
count.orderByAggregate('COUNT', 'producer');
count.query();
while (count.next() && producers < limit) {
var catalogItemJS = new sn_sc.CatItem(count.getValue('producer'));
if (!catalogItemJS.canView() || !catalogItemJS.isVisibleServicePortal())
continue;
var catItemDetails = catalogItemJS.getItemSummary();
var item = {};
item.order = 0 - count.getAggregate('COUNT', 'producer');
item.name = catItemDetails.name;
item.short_description = catItemDetails.short_description;
item.picture = catItemDetails.picture;
item.price = catItemDetails.price;
item.hasPrice = item.price != 0;
item.sys_id = catItemDetails.sys_id;
item.page = 'sc_cat_item';
items.push(item);
producers++;
}
return items;
}
})();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2022 01:34 AM
does the url changed?
is there any error message?
Do you see any error in the browser console?
And after cloning OOTB widget what changes you made on the cloned widget?
Regards,
Vamsi S