Expanding out sub categories in the SC Category widget in the Service catalog

bretelson_patri
Kilo Contributor

I am attempting to expand parent sub-categories in the SC Category widget in the Service Catalog.  Has anyone accomplished this?  Below are screenshots of what the SC Category widget looks like now by default on the left and what I would like too accomplish for the default view on the right.

find_real_file.png     find_real_file.png

2 REPLIES 2

sachin_namjoshi
Kilo Patron
Kilo Patron

You can have look into OOB widget available for hierarchical widget code.

 

https://docs.servicenow.com/bundle/kingston-servicenow-platform/page/build/service-portal/concept/org-chart-widget.html

 

Regards,

Sachin

Ximizu
Mega Guru
Hi bretelson_patrick@bah.com,
 
You can achieve this in 2 steps:
 
1. Clone the widget "SC Category"
2. In the server script, replace the line

categoryDetails.showChildren = (categoryDetails.sys_id === categoryId);​

by

categoryDetails.showChildren = (categoryDetails.sys_id === categoryId || categoryDetails.sys_id == '<sys_id of the category you to expand by default>');

e.g.
//XHU 04/01/18 - Always Display children of category "Service Utilisateur" - 95ff5835dbbfe60084e7bc2ffe9619aa 
		categoryDetails.showChildren = (categoryDetails.sys_id === categoryId || categoryDetails.sys_id == '95ff5835dbbfe60084e7bc2ffe9619aa');​

Before I perform the modification, the categories are all collapsed when I go to the service catalog homepage

find_real_file.png

 

After I have performed the 2 steps described aboved, the category "Service Utilisateur" is expended by default when I go to the service catalog homepage

find_real_file.png

 

Since is not much recommend to hardcode sys_id in the script, I would even go further to put the category sys_id as an instance options of the widgets.

 

Ximizu

Co-founder of CloudSpirit