Article View Counts After Vancouver?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2024 12:43 PM
I've been researching how the View Count is calculated for a knowledge article, but at the bottom of several articles, I see a note saying "Beginning Vancouver release, glide.knowman.view_age.days and Count Knowledge scheduled job is deprecated."
I can't find any information on how View Counts are calculated from Vancouver moving forward, though. We're currently on Vancouver, and both items are still there and seem to be functioning as expected. Will this go away at some point?
- Labels:
-
Knowledge Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2025 03:10 PM - edited 02-10-2025 03:39 PM
I had the same question and, since no one else had done a dive and I didn't see anything on the Docs site, I dove through some code. This isn't a complete dive and parts may be incomplete or slightly incorrect. If I have more time, I'll update this more later.
Yes, the Knowledge Management properties ServiceNow Docs seems to be accurate The Scheduled Job is no longer performing a nightly summation of the "Knowledge Use [kb_use]" Records over a period of days as set by the glide.knowman.view_age.days.
Per that ServiceNow Docs, "The View count of an article does not have a rolling count, the existing view count gets incremented for every article view". This means "View count [sys_view_count]" will reflect the the total over the entirety of the Article's life -- not just the last x days. (Which, if you are like us, is disappointing as it means older Articles will always appear to be more useful to users even if a new Article is actually getting more interest.)
They don't document how it is calculating that -- hence this dive.
It seems places that typically display Article content, such as the "kb_view" UI Page (/sys_ui_page.do?sys_id=11efa742eb4221007128a5fc5206fe1a) and the "Knowledge Article Content" Widget (/sp_widget.do?sys_id=a47ea1cb0b9432004ce28ffe15673a5b) displayed on Portals, have been updated. They call the "KBViewModel" Script Includes (/sys_script_include.do?sys_id=994116f1d73221004792a1737e610371) which is an extension of the "KBViewModelSNC" Script Includes (/sys_script_include.do?sys_id=aef116f1d73221004792a1737e6103a4).
increaseKBView: function(knowledgeRecord) {
if (!this.isPreviewArticle() && knowledgeRecord && knowledgeRecord.isValid()){
knowledgeRecord.incrementViewCount();
new sn_ais.IndexEvent().queueUpdatableFieldAction('kb_knowledge', knowledgeRecord.getUniqueValue());
}
},
So if you aren't previewing the article (i.e. You have clicked the "View Article" UI Action from the Related Links in the Article resulting in it showing the "kb_view" Page with "&preview_article=true" as part of the URL) and we're on a valid Knowledge Article, then it increments the "View count [sys_view_count]" field of the Article.
If you have written your own Page or Widget to display Articles or have modified the original Pages or Widgets, you will want to make sure it calls that KBViewModel code correctly to ultimately call that "increaseKBView" function. (Use the "out of the box" code as an example of what functions to call.)
If you want to change the behavior of how "View count [sys_view_count]" is calculated (e.g. disabling the function and recreating the Scheduled Job to return to the previous behavior) , you can override the function in the "KBViewModel" Script Includes... but be wary of unintended consequences.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2025 05:52 PM
Just spitballing here, but would it be at all useful to create a new (hidden) field, and increment it alongside the other count? I'm probably over complicating it, but you could create a kb_knowledge child table, adding in two fields: a new integer count field & a Date field. Build a Scheduled Job that runs at the end of the day(or whatever time frame you like), counts the views from that time period, and then logs them by making a new record on the child table. Then, generate a report that displays views for specific articles over a certain time period. Doing this would generate data on which articles have been used the most over the last month, six months, whatever.
Again, I might be overcomplicating it. But it *is* an idea!
If I've at all helped, please return the favor by clicking the thumb next to my post. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2025 09:16 AM
Depends on your use case but I personally wouldn't add a field for a few reasons and, if I did want to add a field, I wouldn't extend "Knowledge [kb_knowledge]" to do that for a few additional reasons
The reason for updating using the "View count [sys_view_count]" field would be if you wanted that to be displayed to users on the Portal, Next Experience, etc. If you add a field, you would have to update all those Widgets / Pages / etc. reference that bespoke field use the bespoke field which is a lot of customization (I suspect some of it isn't even available to us as customers to modify).
If you only want it for reporting, then you can get that in real time by creating a Pivot Report on the "Knowledge Use [kb_use]" Table. The only downside is you can't easily filter it to just Published Articles since you will likely want to set your Row to Article.Number so that they group by Number instead of splitting out for each Verson... and some of those Versions may no longer be Published but you'd still likely want them in your tally of usage. Hence being unable to simply filter to where "Article.Workflow = Published" as you'd exclude the views of older Versions of the Article. (I will warn that you probably don't wan to put this on a frequently loaded Dashboard as, depending on your Knowledge usage, this may be a slow Report to run).
If you do end up adding a field because the Pivot Report doesn't meet your needs, I personally wouldn't extend the "Knowledge [kb_knowledge]" Table just to add a field. Especially as, with Xanadu, all new customers will have and many existing customers will choose to use Knowledge Management Advanced and Knowledge Article Templates. Article Templates are extended from Knowledge so you'll find yourself having to extend each Article Template Table individually and then you won't be able to create that holistic reporting on Knowledge you're likely after -- you'd have to report on each Table extended from each Article Template. So prob best to just add a Dictionary Entry on the root "Knowledge [kb_knowledge]" Table so that it applies to all child Tables and then use/update the old "Count Knowledge Use " Scheduled Job (as someone has copied in this Problem with Count Knowledge Use script - does not run when glide.knowman.view_age = 0 Community Post) to populate it. But again, that would only be for Reporting and only if the above Pivot Report doesn't work. If you're trying to display to the users, consider how best to do that for your company: disabling the code populating "View count [sys_view_count]" and replacing it with the Scheduled Job (which will return the old behavior at the cost of deviating from ServiceNow's current ways of working) or creating a new field and populating it with the Scheduled Job (at the cost of having to customize a number of Widgets, Pages, etc. to replace displaying "View count [sys_view_count]" with your custom field.)