How are knowledge article use count and view count added in kb_use table from attach to incident

lakshmir
Giga Contributor

Hello all,

The article view count and use count increases each time the article is attached to incident.

It is out of box functionality.Can somebody explain from where it triggers to increase the count.

1 ACCEPTED SOLUTION

andrew_venables
ServiceNow Employee
ServiceNow Employee

Hi Lakshmi,



The 'Attach to Incident' button comes from the UI Macro called 'kb_view_attach_button'.



Which calls a client JavaScript function named 'attachIncident2' in the UI Script 'KnowledgeFunctions'.



This in turn calls the function 'kbAttachArticle' of a Script Include called 'KnowledgeAjax'.



Inside the script include, an event is fired called kb.use and this event is picked up by a System Policy>Script Action named 'Knowledge Use' which creates a new record in the kb_use table indicating the kb has been used in an incident.



The use_count field on the kb_knowledge table isn't actually used for keeping this count, although you could quite easily use a business rule on the kb_use table to keep it sync'd.



The view count is stored in the sys_view_count field of the kb_knowledge record and is incremented whenever the article is viewed via kb_view.do



Hope this helps



Andy


View solution in original post

9 REPLIES 9

Bhavesh Jain1
Giga Guru

View Count and Use Count are the integer fields of table kb_knowledge.



Whenever any article is previewed, UI page kb_preview opens and executes below code to increment the view count.



  var kb = new GlideRecord('kb_knowledge');


  kb.initialize();  


  kb.get(jelly.sys_kb_id);


  if (kb.short_description.nil())


    kb.short_description = '(' + gs.getMessage('Short description empty') + ')';


  gs.eventQueue('user.view', kb, kb.getDisplayValue(), gs.getUserID());


  gs.eventQueue('kb.view', kb, kb.getDisplayValue(), gs.getUserID());


  kb.incrementViewCount();



Whenever any article is opened(not preview) , UI page kb_view opens and executes below code.



<!-- outputs an article's footer info: link, viewcount -->


    <table class="wide" cellspacing="0">


      <tr><td style="color:#999999; font-size:80%; padding-top:8px;">


        <g:inline template="kb_article_footer.xml" />


                    </td></tr>


    </table>



kb_article_footer.xml is the inbuilt page they have designed which calculates the view count.


Thank you:)


Hi Bhavesh.

Whenever any article is previewed the view count number increments. Does it mean that the view count number increments across all article versions? So, the view count visible on the latest KB article version form is a cumulative value from all article versions?

Example:

Article Version 1 - 4 views

Article Version 2 - 10 views = 4 views(from version 1) + 6 views (version 2)

Article Version 3 - 12 views = 10 views (from the version 1 and 2) + 2 views (version 3)

Lola B
Kilo Expert

FYI - I heard Use Count will be fixed in Jakarta...yea!


Hi Everyone!



i have a question, in our DEV environment the kb_use.viewed is getting updated to true according to the view count, but in our QA and prod. it doesn't (stays as false regardless to the view count).


we cloned QA and DEV at about the same time (1 day apart) after knowledge V.3 and upgrading to Jakarta.


any clues on where i can find the missing link?



thanks!


M