Change knowledge article view count calculation so that it doesn't increment view count when article is not published.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2020 11:54 AM
Has anyone had experience doing this? From what I understand there are different system views which trigger an event called kb.view which then increments the view count based on viewing a knowledge article in the ess. But when it's viewed in the SP there is something else which increments the view. My issue is that it doesn't really make sense that the system should increment the view count of an article when it's not in a published state. While knowledge articles are being drafted they tend to be viewed multiple times by the author and approvers to insure that they are presentable to end users once they are published. So by the time an article is published it has tons of views which are really false positives and it throws the actual view count off. I'd like to make it so that it only increments the view count when the workflow_state is published.
Any pointers would be greatly appreciated.
- Labels:
-
Knowledge Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2020 12:19 PM
It's not the cleanest solution, but a simple Business Rule could accomplish this.
Create an after update BR on kb_knowledge, set you conditions to run when the workflow_state changes to Published. In the script field, something this should work (not tested):
var gr = new GlideRecord("kb_use");
gr.addEncodedQuery("article=" + current.sys_id);
gr.query();
if(gr.next()) {
gr.deleteMultiple();
}
This won't immediately clear out the view count, as those are updated every evening by the Count Knowledge Use scheduled job. Once that job runs, the view count will have updated to show an accurate view count.
I'm sure there other ways of doing this, but with this you're not changing any of the OOB configurations which should keep your patching/upgrades simple.
Hopefully this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2020 12:22 PM
Hi
I agree it is a bit odd how it contributes to the View count when the Author is viewing it over and over. Perhaps a new Idea on the Idea Portal is in order.
Anyway, I did some searching and yes, this will come from the "kb.view" event.
I found that there are 3 places that reference this event in the code. You may want to look into these and perform some validation before they execute:
UI Page "kb_preview" (line 13)
Script Include "KBViewModelSNC" (lines 1083 and 1086). Will need to override in "KBViewModel" This looks like where it determines if it is invoked by the Service Portal
Script Include "KnowledgeHelpSNC" (lines 53 and 109). Will need to override in "KnowledgeHelp"
Hope that helps!
If it did, please mark as Helpful and consider setting the reply as the Correct Answer to the question, thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2020 01:08 PM
That's a great idea about the Idea Portal. Thanks so much for your help, I'm going to start digging in those areas and see what I can work out.
Cheers.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2020 01:30 PM
My pleasure
Would you be willing to mark my previous response as the Correct Answer so that any other people looking for a similar question will be able to quickly find this post? Thanks!