KB Most Viewed widget tweak to display from multiple knowledge bases

wbwb
Tera Expert

Does anyone know how to update the existing KB Most Viewed Articles widget's code to pull from multiple knowledge bases?  Using Jakarta.

 

(function() {
 data.articles = [];
 options.title = options.title || gs.getMessage("Most Viewed Articles");
 var z = $sp.getKBRecord();
 z.addQuery("sys_view_count", ">", "0");
 if (options.kb_category)
  z.addQuery("kb_category", options.kb_category);
 z.orderByDesc('sys_view_count');
 z.setLimit(options.max_number || 5);
 z.query();
 while (z.next()) {
  if (!z.canRead())
   continue;

  var a = {};
  $sp.getRecordValues(a, z, 'short_description,sys_view_count,sys_id,published');
  data.articles.push(a);
 }
})()

1 ACCEPTED SOLUTION

Mark Stanger
Giga Sage

I don't have an easy solution for you with a from-scratch widget, but there is a pretty simple solution using a widget that ServiceNow has already built.

The Knowledge Management Service Portal plugin improves significantly upon the Service Portal KM capabilities...particularly around handling multiple knowledge base scenarios like this.  It's included in Jakarta and is easy to activate and use.  You should be able to turn it on and just use their enhanced widget to solve your problem if you wanted without impacting your existing service portal.

https://docs.servicenow.com/bundle/jakarta-servicenow-platform/page/product/knowledge-management/concept/knowledge-management-service-portal.html

'Knowledge MostViewed Articles' is the name of the widget you'll want to use once you've activated the plugin.  It includes most viewed articles from all Knowledge Bases by default, but you can restrict it with a simple option change to whatever KBs you want.

You can get a bunch of really nice additional functionality if you fully integrate the new portal into your existing portal though so you might want to check that out as well.  Here are the instructions for integrating the 2 portals.

https://docs.servicenow.com/bundle/jakarta-servicenow-platform/page/product/knowledge-management/concept/conf-service-portal-know-management.html

View solution in original post

6 REPLIES 6

wbwb
Tera Expert

Thanks, I was only aware of the Advanced Knowledge plugin.  Looks like this plugin should almost be a default if you're going to use Knowledge at all.

I agree.  If I were setting up a new portal today I'd have it enabled for sure.

Let me know if you have any other questions on this.  If I've answered your question, please mark it above.  Thanks!