Announcing the Global SNUG Board of Directors. Learn more here
Finally I got sometime to finish off the Multiple Catalog series. In this part let's delve into search and breadcrumbs.
As we know the OOB Homepage and typeahead Search widget supports only single catalog. In order to support the search for multiple catalogs, we need to clone typeahead search widget and give an unique name to widget id.
And in server script getCatalogItems function need to updated.
function getCatalogItems() {
var catalogs = [];
var sc_cat = new GlideRecordSecure('sc_catalog');
sc_cat.addQuery('active', true);
sc_cat.query();
while(sc_cat.next())
{
catalogs.push(sc_cat.sys_id.toString());
}
var sc = new GlideRecord('sc_cat_item');
sc.addQuery(textQuery, data.q);
sc.addQuery('active',true);
sc.addQuery('no_search', '!=', true);
sc.addQuery('visible_standalone', true);
sc.addQuery('sys_class_name', 'NOT IN', 'sc_cat_item_wizard');
sc.addQuery('sc_catalogs', catalogs);
sc.query();
var catCount = 0;
while (sc.next() && catCount < data.limit) {
if (!$sp.canReadRecord(sc))
continue;
var item = {};
if (sc.getRecordClassName() == "sc_cat_item_guide")
item.type = "sc_guide";
else if (sc.getRecordClassName() == "sc_cat_item_content") {
var gr = new GlideRecord('sc_cat_item_content');
gr.get(sc.getUniqueValue());
$sp.getRecordValues(item, gr, 'url,content_type,kb_article');
item.type = "sc_content";
}
else
item.type = "sc";
$sp.getRecordDisplayValues(item, sc, 'name,short_description,picture,price,sys_id');
item.score = parseInt(sc.ir_query_score.getDisplayValue());
item.label = item.name;
data.results.push(item);
catCount++;
}
}
Once this widget is created, use the new widget ID in homepage search widget
data.typeAheadSearch = $sp.getWidget('new-typeahead-search', typeAheadSearchOpts);
Once the widget is successfully created use the new typeahead search widget across all the pages.
Breadcrumbs
To point the correct breadcrumbs we have update the client controller in following widgets
Here is the sample script for multi SC categories client controller
var bc = [{label: 'Catalogs', url: '?id=multi_catalog'}];
if ($scope.data.sc_catalog) {
bc[bc.length] = {label: $scope.data.catalog_name, url: '#'};
}
$rootScope.$broadcast('sp.update.breadcrumbs', bc);
This concludes multiple catalog functionality in Service Portal.
Previous Blogs in this series
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.