Sc Categories widget for the portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2020 02:29 AM
Using the latest version of the sc categories widget on the portal, I want to clone and add to specific page. On this page, I only want it to show 1 catalog and its underlying categories. I have seen a few articles on here but they all appear to be related to an older version of the widget.
Im thinking I need to update this part of the server script:
(function() {
var catalog_id = $sp.getParameter("catalog_id") ? $sp.getParameter("catalog_id") + "" : "-1";
var catalogSelectorArr = [{value: "-1", displayValue: gs.getMessage("All")}];
data.selectedCatalogIndex = catalog_id == -1 ? 0 : -1;
var catalogIDs = $sp.getCatalogs().value + "";
var catalogs = catalogIDs.split(",");
var isCatalogAccessibleViaPortal = catalog_id == -1 ? true : false;
catalogs.forEach(function(catalogSysId) {
if (catalog_id == catalogSysId) {
isCatalogAccessibleViaPortal = true;
}
});
But as my scripting isnt up to scratch, I am not sure where I would need to define the specific catalog sysId
Any help would be appreciated.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2020 07:29 AM
Hey Matt,
All you should need to do is define the catalogIDs variable to the sys_id of the Catalog you want to limit it to.
Search "Catalogs" in the Filter Navigator and choose "Maintain Catalogs"
This should take you to a list view of all the Catalogs. Find the one you want to limit to, and right-click on it, and select "Copy sys_id"
Now put that sys_id in the code below where you're defining catalogIds, replace {{SYS ID HERE}} below
(function() {
var catalog_id = $sp.getParameter("catalog_id") ? $sp.getParameter("catalog_id") + "" : "-1";
var catalogSelectorArr = [{value: "-1", displayValue: gs.getMessage("All")}];
data.selectedCatalogIndex = catalog_id == -1 ? 0 : -1;
var catalogIDs = {{SYS ID HERE}};
var catalogs = catalogIDs.split(",");
var isCatalogAccessibleViaPortal = catalog_id == -1 ? true : false;
catalogs.forEach(function(catalogSysId) {
if (catalog_id == catalogSysId) {
isCatalogAccessibleViaPortal = true;
}
});
Let me know if that works out for you!
If my answer was helpful or solved your issue, please mark it as "Helpful" or "Correct"
Thanks,
Josh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2020 08:11 AM
Thanks. Unfortunately, that only gets me half way there as then when I click on a category under the catalog, it then throws a message saying that I dont have the permission to view the catalog.
Thanks
Matt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2020 08:47 AM
Gotcha, so this Catalog isn't actually associated to the Portal you are trying to view it in?
We'll have to modify the SC Categories widget script a little more to remove that check, and also Clone and edit the SC Category Page widget. These two widgets check to make sure that the Catalog is associated to the Portal. I'm assuming you're wanting this page to operate separately from the Catalogs associated to the Portal so it doesn't clutter up the Service Catalog page. Do note that the users won't be able to search for these items if we go this route.
Basically we are going to remove that validation from the scripts in those widgets. We're actually going to put that SYS ID of the catalog item in the URL, since I think that allows you to reuse this a little better if you want to do different catalogs in the future. Change the beginning of the server scripts to this
SC Categories - Server script:
(function() {
var catalog_id = $sp.getParameter("catalog_id") ? $sp.getParameter("catalog_id") + "" : "-1";
var catalogSelectorArr = [{value: "-1", displayValue: gs.getMessage("All")}];
data.selectedCatalogIndex = catalog_id == -1 ? 0 : -1;
var catalogIDs = catalog_id;
var catalogs = catalogIDs.split(",");
var isCatalogAccessibleViaPortal = true;
var counter = 1;
SC Category Page - Server script
(function() {
if (input && input.category_id)
data.category_id = input.category_id;
else
data.category_id = $sp.getParameter("sys_id");
data.catalog_id = $sp.getParameter("catalog_id") ? $sp.getParameter("catalog_id") + "" : "-1";
var catalogsInPortal = data.catalog_id;
var isCatalogAccessibleViaPortal = true;
var catalogDisplayValue;
and then, when you're linking to this page add &catalog_id={{SYS ID HERE}} to that URL. Example:
dev.service-now.com/sp?id=sc_category&catalog_id=742ce428d7211100f2d224837e61036d
I was able to get this to work for a catalog that was not associated to my Portal in a dev instance, let me know if this is what you're looking for.
If my answer was helpful or solved your issue, please mark it as "Helpful" or "Correct"
Thanks,
Josh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2020 07:33 AM
Hey Matt,
Any luck? Let me know if you still need help!