MB26
ServiceNow Employee
ServiceNow Employee

Alright the title may sound a little odd, but I think the concept is kind of cool. Many years ago I talked to some people at Microsoft who had an internal operations knowledge base called "Octane" (if I remember the name correctly). One concept they utilized really stood out to me. They made their Knowledge base very modular. Within one of their operations group when an incident occurred they would reference a "TSG" or Trouble Shooting Guide to follow steps to resolve the incident. Now there may be tons of TSG's that talk about restarting a particular service, or rebooting a server, or whatever. Rather than assume everyone knew how to restart a service or reboot the server, they would create a step by step process to accomplish this task.

By now you may be saying that if an operations person does not know how to restart a service, they should not be working there. Don't worry about that, I am just trying to get the concept across.


If you can imagine the amount of TSG's that potentially would make reference to how to restart a service. That would be an immense amount of duplicate documentation. So they modularized. When creating a new TSG, if needed, it would reference the step by step process how to restart a service. The key is that it was not a link that took them to another page, but rather an in-line link that opened up the process within the KB article.

This similar concept is what I have created. Here is the simplicity visually. I create a KB Article and create a couple links in it like so.
find_real_file.png

When I then click on one of the links, a box opens up below containing the KB content in-line to the article. Click on the link again, and the box goes away.
find_real_file.png

Now this is merely a simple example with little or no formatting involved. The key is wherever you place the link, the reference KB text will appear immediately below. Here is how I did it.

Modify an Existing UI Script
Whenever a Knowledge article is loaded, it also loads a UI Script called "KnowledgeFunctions". So we merely add in some javascript functionality into this file, and boom, it loads when the article loads as well. Here is what you will need to append to the end of the file.



addLoadEvent(KBArticleReferenceLink);

function KBArticleReferenceLink(){
$$('a[href^="#KBREF_"]').each(function(item){
item.on("click", function(event){
var lk = event.target;
if(lk.next() && lk.next().hasClassName("kbarticlecontent")){
lk.next().remove();
}
else{
var kbid = lk.href.substring(item.href.lastIndexOf("#KBREF_")+7);
var kcah = new GlideAjax('KnowledgeCustomAjaxHelpers');
kcah.addParam('sysparm_name','getKBText');
kcah.addParam('sysparm_kb_number', kbid);
kcah.getXML(setKBArticleReferenceLinkText, null, lk);
}
});
});
}

function setKBArticleReferenceLinkText(response,elem){
var answer = response.responseXML.documentElement.getAttribute("answer");
//alert(answer);
var content = document.createElement("p");
content.setAttribute("class", "kbarticlecontent");
content.style.border="1px solid black";
content.style.padding="10px";
content.innerHTML = answer;
elem.insert({
after: content});
}


Create a new Script Include
We need a script include to facilitate an ajax call to get the text of a KB article.

Name: KnowledgeCustomAjaxHelpers
Client Callable: True


var KnowledgeCustomAjaxHelpers = Class.create();

KnowledgeCustomAjaxHelpers.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getKBText: function(){
var kb_number = this.getParameter("sysparm_kb_number");
var kb = new GlideRecord("kb_knowledge");
kb.addQuery("number", kb_number);
kb.query();
if (kb.next()) {
return kb.text;
}
else{
return "No KB Article Found";
}

},

type: 'KnowledgeCustomAjaxHelpers'
});


Finally add links into your KB article this way
When you add a link into your KB article you would click on the link icon and get this window.
find_real_file.png

The Link URL needs to start with #KBREF_ followed by the KB article number like so. #KBREF_KB0000017

View your KB Article and give it a go..... In-line KB Article Reference.

Enjoy!

<script></script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22945975-1']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

2 Comments