Sorting the Knowledge Categories in your Portal

Carl Fransen1
Tera Guru

Hi All,

We recently had to fix this issue and figured I'd share it in case others have come across this - or might have a better solution.

We've on Jakarta Patch5.   In the Portal (either /sp or in our case/hrportal) the Knowledge categories aren't sorted at all, they seem to be in a random order.   As there is no 'order by' field or ability to order through the interface we updated the widget itself, KB Categories - KBv3, to allow for this - we copied the OOTB widget and created our own and added the lines 4-7 shown below in the 'Client Controller' code.

knowledge_sort2.JPG

knowledge_sort1.JPG

Hope this helps someone out there!  

1 ACCEPTED SOLUTION

sethhumphrey
Mega Guru

Your code didn't work for me but it did get me thinking about it.  Try inserting the following code near the bottom of the Server Script:

  data.categories.sort(function(a,b) {
		return (a.label.toLowerCase() > b.label.toLowerCase()) ? 1 : ((b.label.toLowerCase() > a.label.toLowerCase()) ? -1 : 0);
	});

 

find_real_file.png

View solution in original post

4 REPLIES 4

sethhumphrey
Mega Guru

Your code didn't work for me but it did get me thinking about it.  Try inserting the following code near the bottom of the Server Script:

  data.categories.sort(function(a,b) {
		return (a.label.toLowerCase() > b.label.toLowerCase()) ? 1 : ((b.label.toLowerCase() > a.label.toLowerCase()) ? -1 : 0);
	});

 

find_real_file.png

Hi Seth,

That worked really well for me and I assume as it's server side has no impact on the client loading times either.

Will definitely use this instead in production.

 

Now I'm having the same issue with the articles themselves - they aren't displayed in any order - would you know where I could update code to have these also alphabetically ordered?

 

Thanks

Carl.

I have used the original code you provided and created the sorting successfully for the Documents as well - this means updating the 'KB Category Page' with the new code on the ;server source', code is below under the new commented section:

 

function showStarRating() {
	if (options.show_star_rating == "Yes")
		return true;

	if (options.show_star_rating == "No")
		return false;

	if (gs.getProperty("glide.knowman.show_star_rating", "true") != "true")
		return false;

	return gs.hasRole(gs.getProperty("glide.knowman.show_star_rating.roles"));
}

//Code to sort documents by title
  data.items.sort(function(a,b) {
		return (a.title.toLowerCase() > b.title.toLowerCase()) ? 1 : ((b.title.toLowerCase() > a.title.toLowerCase()) ? -1 : 0);
	});

I have managed to get the server cod working better - see my latest update in a similar thread:

 

https://community.servicenow.com/community?id=community_question&sys_id=2438061ddba91b047b337a9e0f96...