KB Category listing widget empty
Recently updated to Istanbul 8 and discovered a problem with our olders KB Widgets, specifically the ones handling KB Categories.
It appears the old API getKBCategoryArticles is no longer available and should be changed to getKBCategoryArticleSummaries.
The category information listing widget went from:
data.items = $sp.getKBCategoryArticles(data.category);
to
data.items = $sp.getKBCategoryArticleSummaries(data.category, 0, 250);
The category list that shows categories with articles and the amount of articles was not as "easy" to fix (easy in quotation marks as the documentation of this feature change is, as far as I have found, non-existant) so I created a short and very simple Script Include.
Earlier code:
var arts = $sp.getKBCategoryArticles(cats.getUniqueValue());
articleCount = arts.length;
New code:
var arts = new getCategoryArticles().getCategoryArticleNumbers(cats.getUniqueValue());
articleCount = arts; // Please not that .length is no longer used
Script Include:
var getCategoryArticles = Class.create();
getCategoryArticles.prototype = Object.extendsObject(AbstractAjaxProcessor, {
type: 'getCategoryArticles',
getCategoryArticleNumbers: function(cat) {
var art = new GlideRecord('kb_knowledge');
art.addQuery('u_state','Published'); // We have an old field to easily get the state of an article
art.addQuery('kb_category',cat);
art.query();
return art.getRowCount();
},
Hopefully this helps someone else out there.
I made some changes to your script include above to make it more efficient and Server side.. hope you are ok with that
var getCategoryArticles = Class.create();
getCategoryArticles.prototype = {
initialize: function() {
},
getCategoryArticleNumbers: function(cat) {
var count = new GlideAggregate('kb_knowledge');
count.addAggregate('COUNT');
count.query();
count.addQuery('workflow_state', '!=', 'retired');
count.addQuery('kb_category',cat);
count.query();
if (count.next())
return count.getAggregate('COUNT');
},
type: 'getCategoryArticles'
};
https://www.servicenow.com/community/developer-articles/kb-category-listing-widget-empty/ta-p/2295544