Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Understanding how knowledge article views are counted

Ro5
Tera Expert

hello.
Regarding the number of views counted when reading a knowledge article, I would like to customize it as follows.

・Do not count up the number of views when the browser is updated.

・Do not count up when a user with a specific role browses.

Where should I customize?

Thank you.
Ro

1 ACCEPTED SOLUTION

Harish KM
Kilo Patron
Kilo Patron

Sorry forgot to mention widget part. If you look at Knowledge article content widget in server script the below line

// this function is called by script include KBViewModel and function KBViewModel. So you need to find a way to modify here

function handleViewCountIncrement(){
    var incrementedViewCount = new global.KBViewModel().KBViewModel(knowledgeRecord);
    if(incrementedViewCount)
        data.viewCount = parseInt(incrementedViewCount); // this is the count shown on article widget called in HTML part
}

Regards
Harish

View solution in original post

7 REPLIES 7

Harish KM
Kilo Patron
Kilo Patron

Hi you need to check script include KBViewModelSNC in this there is a below function which does this

increaseKBView: function(knowledgeRecord) {
        if (!this.isPreviewArticle() && knowledgeRecord && knowledgeRecord.isValid()){
            knowledgeRecord.incrementViewCount();
            new sn_ais.IndexEvent().queueUpdatableFieldAction('kb_knowledge', knowledgeRecord.getUniqueValue());
        }
    },

Regards
Harish

Mark Manders
Mega Patron

Can you also let us know what didn't work from the links provided to you on your duplicate question? That helps when providing the answer you are looking for (even better if you would just update that question with that info, so everyone would know what information you already have). Can you close the duplicate one?

If my answer helped you in any way, please then mark it as helpful.

Mark


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Harish KM
Kilo Patron
Kilo Patron

Sorry forgot to mention widget part. If you look at Knowledge article content widget in server script the below line

// this function is called by script include KBViewModel and function KBViewModel. So you need to find a way to modify here

function handleViewCountIncrement(){
    var incrementedViewCount = new global.KBViewModel().KBViewModel(knowledgeRecord);
    if(incrementedViewCount)
        data.viewCount = parseInt(incrementedViewCount); // this is the count shown on article widget called in HTML part
}

Regards
Harish

hello. Harish KM
Thank you for your reply.
When I checked, the script include did not have the following functions.
increaseKBView: function(knowledgeRecord) {
         if (!this.isPreviewArticle() && knowledgeRecord && knowledgeRecord.isValid()){
             knowledgeRecord.incrementViewCount();
             new sn_ais.IndexEvent().queueUpdatableFieldAction('kb_knowledge', knowledgeRecord.getUniqueValue());
         }
     },

When I checked the actual knowledge article screen, the number of views was not displayed.

find_real_file.png
Is it because my settings are wrong?

Thank you.
Ro