How to change Knowledge Most Viewed Articles Widget from an ALL TIME view count?

Michael QCKM
Tera Guru

It seems to me every time I check, that the Knowledge Most Viewed Articles Widget is an ALL TIME view count. This is not optimal, and I wonder if it can be changed.  If yes, How?

Example Scenario:

  • In January 2012, there was a Virus issue, so there was a How to remedy Virus article created and viewed 2000 times (in January)
  • Then by mid-January, the issue was resolved by Tier 3, so there is no longer a virus, BUT...

  • The top Viewed article of all time... in 2013, 2014, and 2016 is still the How to remedy Virus article?... that is dumb.
  • Clearly now, the How to make too much money article is far more important, but the Virus article has more Views.

There should be a setting on this widget to allow for a time range, like most other widgets - default of 30 days, but changeable (by the viewer of the widget?) to today, past 7 days, past 30 days, past year, all time).

Is there a setting like that for the widget?  Can there be?  Am I crazy for even considering this as a standard KB offering?

1 ACCEPTED SOLUTION

Your admins need to update the widget server to something like this

 

(function() {
	data.articles = [];
	options.title = options.title || gs.getMessage("Most Viewed Articles");
	var z = new GlideAggregate('kb_use');
	z.addAggregate('COUNT', 'article');
	if (options.kb_category)
		z.addQuery("article.kb_category", options.kb_category);
	z.addQuery('sys_created_on', '>=', gs.daysAgo(30)); // Most views in the past 30 Days
	z.orderByDesc('article');
	z.setLimit(options.max_number || 5);
	z.query();
	while (z.next()) {
		if (!z.canRead())
			continue;

		var count = z.getAggregate('count', 'article');
		var a = {};
		a.short_description = z.article.short_description.toString();
		a.sys_view_count = count;
		a.sys_id = z.article.toString();
		a.published = z.article.published.toString();
		data.articles.push(a);
	}
})()

View solution in original post

6 REPLIES 6

shambhu
Kilo Explorer

Hi dvp,

This works cool. But i also need to push article content along with other details. how would i do tat 

Thank you for your script. I have a similar problem. I need to exclude a specific article that has a high view/usage count, but it is still actively being used. We have a KB that our Service Desk attaches to Incidents when they can't find an article that works for that incident which is called, "KB Unavailable." I'd rather not have that sit at the top of the Most Viewed Article list. Is there an easy way to modify your script to exclude a specific article?

Thanks,

Richelle