- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 06-12-2017 12:09 PM
I wanted to share a few ways that you can modify the out-of-box (OOB) the Service Catalog category list (Widget name: SC Categories, ID: this widget has no ID defined OOB). This widget typically acts like a menu and sits on the left hand side of your Service Catalog pages. The following applies to Istanbul version.
For each of the following modifications, you will need to first clone the OOB 'SC Categories' widget and make changes to the clone.
Expanding a Category to Show Subcategories (Child Categories)
Version 1: When a user clicks on a parent category (that has subategories), you want the category to automatically expand to show the subcategories when the user is directed to the category page that he/she has selected.
In the server script of the cloned widget, add the following code:
if (cat.sys_id == $sp.getParameter("sys_id")) {
cat.showSubcategories = true;
var childCategoriesGR = buildSubcategoryGR(cat.sys_id);
cat.subcategories = retrieveCategoriesFromGR(childCategoriesGR);
}
Below is a screenshot on where to add the above code:
Version 2: When a user clicks on a parent category (that has subcategories), you want the category to expand and not navigate away from the current page. You may want this if you have zero items in your top level category - to avoid having users land on an empty or broken page. This also helps if you find the folder icon to be too small to click on and want a more user friendly option.
Step 1: Open the widget in the ServiceNow platform (not the widget editor) and find the Angular Provider that is associated with the widget and open it:
Step 2:
- Update the name of the directive.
- Update the name of the function in the directive.
- Remember to do an Insert and Stay, to make a copy of the original directive.
- Update the 'template' section of the directive code with the following:
'<div ng-class="{\'indent-category\': indentCategory}">' +
// Not a parent category; has NO sub/child categories
'<a class="list-group-item" ng-class="{selected: category.selected}" href="?id={{page}}&sys_id={{::category.sys_id}}" ng-if="!category.isParentCategory">' + '<span ng-if="!omitBadges" class="label label-as-badge label-primary">{{::category.count}}</span>' +
'<i class="fa fa-fw text-muted" ng-class="{\'fa-folder\': !category.showSubcategories, \'fa-folder-open\': category.showSubcategories}" ng-if="category.isParentCategory" ng-click="toggleShowSubcategories($event)"></i>{{::category.title}}' +
'</a>' +
// Yes a parent category that HAS sub/child categories
'<a class="list-group-item" ng-class="{selected: category.selected}" ng-if="category.isParentCategory" ng-click="toggleShowSubcategories($event)">' +
'<span ng-if="!omitBadges" class="label label-as-badge label-primary">{{::category.count}}</span>' +
'<i class="fa fa-fw text-muted" ng-class="{\'fa-folder\': !category.showSubcategories, \'fa-folder-open\': category.showSubcategories}" ng-if="category.isParentCategory" ng-click="toggleShowSubcategories($event)"></i>{{::category.title}}' +
'</a>' +
// Update the recurring template used to this template
'<sp-category-list-item-mod ng-if="category.showSubcategories" ng-repeat="subcategory in category.subcategories" category="subcategory" omit-badges="omitBadges" level="level + 1"></sp-category-list-item-mod>' +
'</div>',
Step 3: In the platform, update the angular provider used by your widget (see screenshot in Step 1), and update the HTML template of your widget to use the new directive that you created in Step 2.
Changing the Folder Icon
If you want to change the icon displayed in the list (example: use chevrons instead of the folder icon) like so:
Follow the steps for version 2 above, but instead of changing the template as stated above, you only need to update the icon specified in the angular directive template. Replace fa-folder and fa-folder-open with the icon styles of your choice
Hopefully the above also gives you a starting point for other customizations you may want to apply for the base SC Categories widget.
Disclaimer: the content above has been collated from various community posts that I have answered. I've posted here so that the answers are easier to find and to read.
- 28,763 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Nia, is there a way when you click a parent category that has no items in it to display a page with a list of all the subcategories under that parent? I implemented your code to not navigate away from the current page when you click a parent, but in this case I want it to behave differently.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I want it to look similar to this (this section under IT to IT Services):
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This is not the most elegant solution by any means but I achieved what you're looking for by hard coding a page ID for the parent category in the spCategoryListItemMod template/angular provider.
'<a class="list-group-item" aria-label="{{::category.title}}" ng-if="category.isParentCategory" ng-class="{selected: category.selected}" href="?id=[INSERT PARENT PAGE ID HERE]&sys_id={{::category.sys_id}}">'
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Nia!
Can you please elaborate on what you did here? What is the best way to find/define the parent category ID dynamically?
Thanks!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Mathias,
Here's a bigger code excerpt so you can see where I hard coded the page ID for the parent category:
'<div ng-class="{\'indent-category\': indentCategory}">' +
// parent category
'<a class="list-group-item" aria-label="{{::category.title}}" ng-if="category.isParentCategory" ng-class="{selected: category.selected}" href="?id=[INSERT PARENT PAGE ID HERE]&sys_id={{::category.sys_id}}">' +
'<span ng-if="!omitBadges" class="label label-as-badge label-primary">{{::category.count}}</span>' +
'<i tabindex="0" aria-label="{{category.showSubcategories ? \'${Collapse subcategories}\' : \'${Expand subcategories}\'}}" class="fa fa-fw text-muted" ng-class="{\'fa-folder\': !category.showSubcategories && !category.selected, \'fa-folder-open\': category.showSubcategories || category.selected}" ng-if="category.isParentCategory" ng-click="toggleShowSubcategories($event)"></i>{{::category.title}}' +
'</a>' +
// NOT a parent category
'<a class="list-group-item" aria-label="{{::category.title}} ${Number of items in this category} {{::category.count}}" ng-if="!category.isParentCategory" ng-class="{selected: category.selected}" href="?id={{page}}&sys_id={{::category.sys_id}}">' +
'<span ng-if="!omitBadges" class="label label-as-badge label-primary">{{::category.count}}</span>' +
'<i tabindex="0" aria-label="{{category.showSubcategories ? \'${Collapse subcategories}\' : \'${Expand subcategories}\'}}" class="fa fa-fw text-muted" ng-class="{\'fa-folder\': !category.showSubcategories && !category.selected, \'fa-folder-open\': category.showSubcategories || category.selected}" ng-if="category.isParentCategory" ng-click="toggleShowSubcategories($event)"></i>{{::category.title}}' +
'</a>' +
'<sp-category-list-item-mod ng-if="category.selected || category.showSubcategories" ng-repeat="subcategory in category.subcategories" category="subcategory" omit-badges="omitBadges" level="level + 1"></sp-category-list-item-mod>' +
'</div>',
You'll have to change [INSERT PARENT PAGE ID HERE] with your own parent page id.
I would imagine there's a way to define it dynamically and pass it in from the widget but I don't as yet know how. I'm afraid I'm not familiar with angular and am learning it as I go. Please feel free to post a question to the community if you're interested in finding out how to make this more dynamic. Perhaps other experts can jump in to help.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi
Any idea on modifying it to display Catalog Items as well beneath each category.
Somewhat like
Category 1
->Subcategory 1
->Subcategory 2
-| Catalog Item 1(Subcategory 2)
-| Catalog Item 2(Subcategory 2)
-@ Catalog Item 1(Category 1)
-@ Catalog Item 1(Category 2)
Thanks
Deepak
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Nia:
I'd like to take the chevrons that you created above (worked like a charm, thanks) and move them to the right of the category title similar to what they have done in docs.servicenow.com. Do you know how I can accomplish that?
Also, I want the Catgories and Subcategories to respect the order field so that I can order present them in something that is non alphabetical.
Appreciate your help.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
To move the chevrons to the right of the category try this:
Remove the code from your Angular provider (directive) as shown below:
'<a class="list-group-item" ng-class="{selected: category.selected}" href="?id={{page}}&sys_id={{::category.sys_id}}" ng-if="!category.isParentCategory">' + '<span ng-if="!omitBadges" class="label label-as-badge label-primary">{{::category.count}}</span>' +
'<i class="fa fa-fw text-muted" ng-class="{\'fa-folder\': !category.showSubcategories, \'fa-folder-open\': category.showSubcategories}" ng-if="category.isParentCategory" ng-click="toggleShowSubcategories($event)"></i>{{::category.title}}' +
'</a>'
Since you're moving the icon to the right, you'll have to remove/replace the 'badges' which show the item count number. So, in place of the above, try the following:
'<span class="label-as-badge"><i class="fa fa-fw text-muted" ng-class="{\'fa-chevron-right\': !category.showSubcategories, \'fa-chevron-down\': category.showSubcategories}" ng-if="category.isParentCategory" ng-click="toggleShowSubcategories($event)"></i></span>'
To sort by the order field instead of alphabetically, you'll likely have to add gr.order('order') in your server script.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
HI Deepak,
Not the best approach but I'd tackle this by adding the query for the items in the Server Script and building the data object to contain the items. You should then be able to use most of the same code for the rest of the widget including much of the Angular provider (directive) code, I think.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello Nia,
I am trying to accomplish the same thing as Mathias. However, as a Widget / SP / Angular noob, I have no idea what you mean by the "parent page ID" - or rather importantly, where can I get that ID from? Could you assist me with where or how I can obtain the ID?
How does it actually look like? I tried to access HTML code from my browser and there is a parameter called data-page-id="07261a2147132100ba13a5554ee49092" which as I tried is the whole page basically.
Maybe a better question is - does this solution require to create a "UI page" or simply "Page" which would contain subcategories of the parent category? And then insert the ID of such page to your code above?
Regards,
Michal
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
The page id is the text name for the page that you want to direct the link to. It's the machine friendly name the SP page like the one highlighted below:
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
HI Nia:
I had asked the rest of the community but I did not get an answer. Hoping you might.
I have a requirement to add mouse over/hover hints to the categories in the SC Categories Widget. I was thinking that I could use the OOB column 'description' in the Catalog Item. It would have a similar behavior as the fields in the standard forms that that display the value in the 'hint' column. like this:
In the same vein, I also want to show the Title And Description at the top of the 'SC Category Page' widget, similar to below.
Thanks
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks Nia, that did the trick.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
https://community.servicenow.com/thread/238470
Please refer to Geoffrey Sage' s answer in the abpve mentioned link.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks for the post Nia, this is very helpful, however a common question that I encounter (and am sure am not alone here) is - on the parent category, how to show a cumulative count of the items contained under each subcategory.
To elaborate - parent category is hardware = 0 items;
subcategory1 - laptop = 3 items
subcategory2 - printers = 5 items
currently it shows 0 against hardware, and if I click on the folder icon, then 3 & 5 against laptop and printers respectively.
I'd want a way to be able to show 8 against hardware, so that the end user knows what to expect.
Thanks in advance!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Sakshi,
This can get very complicated because some items can be listed in the category and the subcategory.
For example:
parent category is hardware = 3 items
subcategory 1 is laptop = 2 items
subcategory 2 is printers = 5 items
And if item1 is listed both in hardware category and laptop subcategory1, then should it count as 1 item or 2?
Would the total be 9 or 10?
Even if you could guarantee that in your organization, every item is only listed in one category or subcategory, I don't know how to achieve this in Jakarta (which is what my instance is now) since the code has been changed to rely on a REST API call. The REST API provides the count for each top level category and doesn't not return counts for the subcategory.
If you're on pre-Jakarta, you may still be able to modify the code in the server script to achieve what you want.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
michalhancar mathiasjohansson scottneeb niamccash - Dear All,
Even I have been looking for solutions where in "when you click a parent category that has no items in it to display a page with a list of all the subcategories under that parent" .
Somehow hard coding the angular directive as Nia suggested didn't work for me (maybe I did mentioned the wrong Page ID)
Please let me know if you have found a way to get this done.
Thank you in advance.
Kind Regards,
Sreejith Nair
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks Nia, that is indeed a valid point. I think I'll just remove the numbers.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Sakshi,
Did you get the count of child categories Items as well. Our client also want same. They want to display total count of Items under all subcategories as well. Please let me know if you have developed same.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi nia,
I have tried applying the changes to a Jakarta instance, with some modifications due to code differences, but I cannot get this to work. Did you manage to get this working on Jakarta or you have any Jakarta code snippets?
Thanks
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I have just managed to get it working. The angular looks as follows:
template: '<div role="listitem" ng-class="{\'indent-category\': indentCategory}">' +
'<a class="list-group-item" aria-label="{{::category.title}} ${Number of items in this category} {{::category.count}}" ng-class="{selected: category.selected}" href="?id={{page}}&sys_id={{::category.sys_id}}" ng-if="!category.isParentCategory">' +
'<span ng-if="!omitBadges" class="label label-as-badge label-primary">{{::category.count}}</span>' +
'<i tabindex="0" aria-label="{{category.showSubcategories ? \'${Collapse subcategories}\' : \'${Expand subcategories}\'}}" class="fa fa-fw text-muted" ng-class="{\'fa-folder\': !category.showSubcategories, \'fa-folder-open\': category.showSubcategories}" ng-if="category.isParentCategory" ng-click="toggleShowSubcategories($event)"></i>{{::category.title}}' +
'</a>' +
'<a class="list-group-item" aria-label="{{::category.title}} ${Number of items in this category} {{::category.count}}" ng-class="{selected: category.selected}" href="#" ng-if="category.isParentCategory" ng-click="toggleShowSubcategories($event)">' +
'<span ng-if="!omitBadges" class="label label-as-badge label-primary">{{::category.count}}</span>' +
'<i tabindex="0" aria-label="{{category.showSubcategories ? \'${Collapse subcategories}\' : \'${Expand subcategories}\'}}" class="fa fa-fw text-muted" ng-class="{\'fa-folder\': !category.showSubcategories, \'fa-folder-open\': category.showSubcategories}" ng-if="category.isParentCategory" ng-click="toggleShowSubcategories($event)"></i>{{::category.title}}' +
'</a>' +
'<sp-category-list-item-mod ng-if="category.showSubcategories" ng-repeat="subcategory in category.subcategories" category="subcategory" omit-badges="omitBadges" level="level + 1"></sp-category-list-item-mod>' +
'</div>',
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Nia,
Can we get sub categories count, add to parent category along with Items count? I am working in Jakarta, can you please help me on this.
Thanks,
Bindu.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Himabindu,
No, I just convinced my clients to remove the numbers. The reason I gave them is - it is possible for an item to be present under multiple categories and as niamccash also highlighted, that would just mess up the numbers. The service catalog is an ever growing/changing entity, so no one can guarantee that the item classification/cat-subcat structure won't change over time. Another thing that helped tip the scales in my favour was the platform upgrade. This change will not be a minor change to the base configurations, and will create problems/require extensive resources during the upgrade.
Hope this helps!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Nia,
I have changed the href to parent page id but still, it is not working please help.
I have created the new page to reflect only one parent category and their sub-category.
But clicking on the parent category(how can we help you), it is taking to old page itself, which i got to know to change in "Angular provider". I have changed the page to page id, but still, it is not working.
When i clicked on parent caterogy it is taking to old page not landing on the new page.
Thanks in advance,
Naveena
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Can you post your code so we can see what you've done?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Nia,
Please let us know how to display for Request Category.
The code is working fine for Incident Category and not RI category.
Please help.
Thanks,
naveena
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thank you for the Reply Nia,
I have made mistake, not changing the function name.
After changing function name in the Angular provider, its working fine.
I have one more query.
What code has to be changed to visible only RI category, by using the above code only Incident Category are visible.
Please help as I'm not the background of coding.
Thanks in advance,
Naveena
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Is there a way to change the color of the categories listed within the widget? (In your example, it would be the words "Departmental Services", "Hardware", etc.) I can't get mine to change from the gray OOTB color.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Yes, you can change the color.
First you need to clone the SC Categories Widget.Then in the below CSS, change the color in a.list-group-item class(higloghted in bold and italics).
.list-group-item {
.fa-fw {
margin-right: 5px;
}
}
.indent-category {
margin-left: 25px;
}
.selected {
color: $primary !important;
}
.list-group {
margin-bottom: 0px;
padding: 10px;
a.list-group-item {
border: 0;
padding: 5px 5px;
margin-bottom: 2px;
color: $link-color;
.badge {
background-color: #0574DE;
border-radius: 1em;
}
}
}
Please mark the reply as helpful or correct in case it helped you.
.list-group-item { .fa-fw { margin-right: 5px; }}
.indent-category { margin-left: 25px;}
.selected { color: $primary !important;}
.list-group { margin-bottom: 0px; padding: 10px;
a.list-group-item { border: 0; padding: 5px 5px; margin-bottom: 2px; color: $link-color;
.badge { background-color: #0574DE; border-radius: 1em; } }
}
Ple
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Naveena H R,
I am also having same use case, to show the Parent category & their subcategory. If you share the way(url) to do that then it would be more helpful.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This worked! Thanks so much!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Dear Nia,
Thank you for the explanation. As you mentioned , can you please let me know using server script how to get the total count of the catalog items in a category which has multiple sub-categories?
THanks ,
Sreejith
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
You should look at the Kingston version of this widget as it is greatly improved. Perhaps you can get the code to come up with the total count from that version of the widget as it does do counts of the category AND the subcategory items.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Kingston upgrade satisfies my requirement.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Anna,
Arrange all the sub-category in one parent category.
In the place of cat.sys_id, put the parent sys_id directly.
if (cat.sys_id == 'YOUR PARENT CATEGORY SYS_ID') {
cat.showSubcategories = true;
var childCategoriesGR = buildSubcategoryGR(cat.sys_id);
cat.subcategories = retrieveCategoriesFromGR(childCategoriesGR);
}
Hope this helps you.
Regards,
naveena
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
i need to remove categories and make appear only catalogue items , i have created a community post for this requirement , kindly help to remove catagories please
https://community.servicenow.com/community?id=community_question&sys_id=f8d07712dbb81b402d1efb651f9619b7
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Has anyone made the version two modification to the kingston widget? I'm having quite a bit of trouble getting it to work in Kingston.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I would encourage you to use the OOB widget in Kingston as it already supports multi level categorization with expandable categories: https://docs.servicenow.com/bundle/kingston-servicenow-platform/page/build/service-portal/concept/sc...
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Nia,
Thank you for the reply! It does all of that for me, yes, however it still allows users to click on the parent categories. In our org, parent categories have 0 items in them. Therefore it would be preferred to modify the widget to only expand subcategories when the parent category has 0 items. That is the only functionality missing from the OOB Kingston widget for us.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
How can I change the order of the subcategories?
Regards,
Pallabi Mitra
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
If there is a problem with subcategories try to solve this with Asus Customer Service that gives you the correct suggestion to access your subcategories this is awesome try this.