- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2019 08:32 AM
Hopefully this is quick and easy!
I am trying to update the breadcrumbs on my portal to get the portal's catalog and not just the first catalog attached to a catalog item (some items are in multiple catalogs).
How do I access this data in a script? I tried $sp.getParameter('catalog') and it didn't work. I am having trouble finding documentation on possible parameters and other get methods for the portal.
Solved! Go to Solution.
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2019 08:33 AM
Here is what I got to work!!! Thank you so much for pointing me in the right direction
Server script-
//current catalog item
data.sc_cat_item = $sp.getCatalogItem(data.sys_id, true);
//get the default catalog from the portal via query
var portalGr = $sp.getPortalRecord().getUniqueValue();//sysId of current portal
var portalcataloggr = new GlideRecord("m2m_sp_portal_catalog");//table which stores portal catalog relation
portalcataloggr.addEncodedQuery('sp_portal.sys_idSTARTSWITH'+ portalGr +'^active=true');
portalcataloggr.query();
//set the name and url for the catalog
if (portalcataloggr.next()) {
data.catalog = {
name : portalcataloggr.getDisplayValue('sc_catalog'),
//SPECIFIY CATALOG HOMEPAGE HERE
url: 'it_sc_category'}
}
//get the current category for the item based on the current catalog
//var catalog = portalcataloggr.sc_catalog;
var categorygr = new GlideRecord('sc_cat_item_category');
categorygr.addEncodedQuery('sc_cat_item='+ data.sc_cat_item.sys_id + '^sc_category.sc_catalog=' + portalcataloggr.sc_catalog );
categorygr.query();
if(categorygr.next()){
data.category = {
name: categorygr.getDisplayValue('sc_category'),
url: '?id=sc_category&sys_id=' + categorygr.sc_category
}
}
client controller-
// Breadcrumbs
if ($scope.data.sc_cat_item) {
var bc = [{label: $scope.data.catalog.name, url: '?id=' + $scope.data.catalog.url}];
if ($scope.data.category)
bc[bc.length] = {label: $scope.data.category.name, url: $scope.data.category.url};
bc[bc.length] = {label: $scope.data.sc_cat_item.name, url: '#'};
$rootScope.$broadcast('sp.update.breadcrumbs', bc);
spUtil.setSearchPage('sc');
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2019 08:48 AM
Can you use server.get() to pull in the data you want in your controller and then reference it server side?
https://serviceportal.io/docs/documentation/widget_server_script_apis.md
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2019 10:54 AM
The client is where the breadcrumbs are set. I was going to get the info in the server side script and then reference it in the controller.
I am looking for the method or script to get the catalog that the portal is currently using in either the client or server script.
In the API I don't see any method specifically for pulling the catalog and i'm not sure how to get it using the other methods that are available.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2019 02:08 PM
This post details how to read the URL of the catalog to pull individual variables in via path parameters. You may be able to do something similar to get that catalog that is currently being used. It seems doable?
https://community.servicenow.com/community?id=community_blog&sys_id=5fdc3377db72e304107d5583ca96198c
I hope this helps somewhat. You raise a good question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2019 10:15 PM
Hi,
Use the below script to get current portals related catalogs.
var portalGr = $sp.getPortalRecord().getUniqueValue();//sysId of current portal
var gr = new GlideRecord("m2m_sp_portal_catalog");//table which stores portal catalog relation
gr.addEncodedQuery('sp_portal.sys_idSTARTSWITH'+ portalGr +'^active=true');
gr.query();
if (gr.next()) {
gs.addInfoMessage("current portals catalog :" + gr.sc_catalog + " "+ gr.getDisplayValue('sc_catalog'));
}
Add additional conditions in encoded query as needed to get correct catalog.
Hope this solves your query!!