Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Adam Stout
ServiceNow Employee
ServiceNow Employee

I often include KB articles in Dashboards via a Content Block to bring in additional explanation into the analytics that the Dashboard displays.   I recently ran into an instance that had the Knowledge Management Advanced plugin enabled which adds versioning to KB articles.   This is great functionality, but it caused an issue with you include a specific KB article into a content block.   With versioning, each version gets its own sys_id so if you use the standard "Show a specific document" type that links to a KB article, you get the version you select but not new versions.

To handle this in your content block, change the type to "Use Script to find a document" and set the script value to this (remember to change the KB article number on line 11):

var latestVersion = function (number)
{
    var gr = new GlideRecord('kb_knowledge');
    gr.addQuery('number','=', number);
    gr.orderByDesc('version.modified_on');
    gr.setLimit(1);
    gr.query();

    gr.next();

    return gr;
};
latestVersion('KB0017035');

 

Comments
muzhda
Tera Expert

adamstout thanks for the script for looking up the current latest version of a KB article.     I created a content block to add to my dashboard to display the details of a specific article, but the content block is not working. Even when i select show a sepecific document, and select a document from the list - the content block doesn't display anything.   Any suggestions?


find_real_file.png



find_real_file.png


Adam Stout
ServiceNow Employee
ServiceNow Employee

Even when you do not use a script, but just select a KB article it isn't being displayed?   Very odd.   Can you open the brwoser debug and see if it is getting some error?


cherylbrownlee
Tera Contributor

I have a similar issue with this script, but at least get a "Detail record could not be located" message. 

 

find_real_file.png

 

find_real_file.png

Adam Stout
ServiceNow Employee
ServiceNow Employee

I recommend putting in a debug statement or two to track down why you aren't seeing anything.  

In the function, between line 7 and 8, add:

gs.addInfoMessage('KB Row Count: ' + gr.getRowCount());

Make sure that is returning something.  You may want to dump out gr.getEncodedQuery() as well to validate everything looks good there.

muzhda
Tera Expert

Adam - i retried the original script you had posted once we upgraded to Kingston and it is working now.  For some reason (i never got around to debugging it) it did not work in Jakarta.

 

Thanks again!!

Adam Stout
ServiceNow Employee
ServiceNow Employee

I don't know what would have changed between Kingston and Jakarta but glad to hear it is working.

flemming1
Giga Contributor

This sounds exactly like what we need, but like muzhda it doesn't work for us in Jakarta.

Anyone else got this working on Jakarta?

Adam Stout
ServiceNow Employee
ServiceNow Employee

I had an interesting experience today.  This appeared to stop working for a dashboard I was working on.  It turns out the original version of this method which sorted on version.version didn't work when there were 10 or more versions because the version was sorting as a string.  Sorting on the modified date (which is different than sys_updated_on) seems to fix it.

CheshireKat
Tera Contributor

Hi Adam

I am trying this in Madrid and not getting any results. Have you made any recent modification with an upgrade to Madrid? This is to be used with the Dynamic Content Block correct?

Thank you!

Adam Stout
ServiceNow Employee
ServiceNow Employee

This was working for me last I used it (a couple of weeks ago on Orlando).  This is not a Dynamic Content block, but a Detail Content block.

David Gerard
Tera Explorer

Would an iFrame content block work just as well - using the sysparm_article=KBXXXXXX instead of the sys_kb_id=xxxxxxxxxxxxxxx parameter as mentioned here: Knowledge article URL parameters  ??

 

Adam Stout
ServiceNow Employee
ServiceNow Employee

I have not tested it but, I don't see why not.  I'm not sure what trade-offs there are between an iframe (where the system doesn't know what it is pulling) and a detailed record pull, but as long as the iframe can resize cleanly (which external data cannot), it is worth a try.

blanca12
Mega Contributor

This sounds exactly like what we need, but like muzhda it doesn't work for us in Jakarta.

 

Kodi nox

Version history
Last update:
‎11-09-2017 02:13 PM
Updated by: