G
reetings from Knowledge12 in New Orleans! I’ll be here all week with CrossFuze Solutions so if you’re here and see me, please introduce yourself. I’m looking forward to putting a face to all of the names of people I’ve worked with remotely.
I’m working with a client currently who wants to encourage the use of their Knowledge Base to reduce their ticket load. This, of course, is a common requirement but it’s one that I don’t think is adequately addressed in ServiceNow currently. In this post I’ll share my implementation of their idea. I don’t think it’s a perfect solution, but it might give you some ideas to improve your own process and design. This post shows how you can force a KB search using the standard search dialog whenever a user creates an incident. I’ve designed the solution to work in a standard incident form and within the service catalog so that it can be applied in whatever way you create tickets in your environment.
When I designed this solution, my main concern was to implement a solution that would promote the Knowledge Base search without being completely annoying to the end user. Because of this, I wanted to be very careful about allowing specific control over the event trigger that produces the KB popup window. I also wanted the solution to use as much of the out-of-box behavior as possible.
The solution I decided on was to use a client script to add a ‘blur’ event to the ‘Short Description’ field. The ‘blur’ event for a field runs when the field loses focus. In the case of the ‘Short Description’ field, it runs when somebody clicks into the field, and then clicks somewhere else. I also wanted the script to only run for a new record and only to run when there was an actual value in ‘Short Description’.
From a Standard Form Field
This script can be pasted directly into any ‘onLoad’ client script on a standard form field. The only requirements are that the form includes a field named ‘short_description’ and that field uses the standard KB search icon.
Name: Pop KB Search from Short Description
Table: Incident
Type: onLoad
Script:
//Set the maximum number of times the popup will appear
var maxKBPop = 1;
var kbPopCount = 0;
//Only run for new records
if(g_form.isNewRecord()){
//Add an 'onBlur' event to search KB from 'short_description' field
var field = g_form.getControl('short_description');
Event.observe(field, 'blur', function() {
//Only search if there is a value
if(g_form.getValue('short_description') != ''){
//Only pop the search one time
if(kbPopCount < maxKBPop){
kbPopCount++;
customKBPopup(field.id);
}
}
});
}
}
function customKBPopup(me) {
self.fillField = me;
var shortElement = gel(me);
var searchText = shortElement.value;
var url = 'kb_find.do?sysparm_search=' + encodeURI(searchText);
url += "&sysparm_nameofstack=kbpop";
url += "&sysparm_kb_search_table=" + g_form.getTableName();
url += "&sysparm_operator=IR_AND_OR_QUERY";
popupOpenStandard(url, 'kb2task');
}
From a Service Catalog Variable
You can also force a KB search with a catalog variable (on a record producer or catalog item). The script below assumes that you’ve got a string field named ‘short_description’. Because the knowledge icon doesn’t exist for service catalog variables, the script manufactures the icon and link on the fly so that it behaves just like the standard field.
Name: Pop KB Search from Short Description
Type: onLoad
Script:
function onLoad() {
//Set the maximum number of times the popup will appear
var maxKBPop = 1;
var kbPopCount = 0;
var field = g_form.getControl('short_description');
//Add the KB Search icon
$(field.id).up(1).insert('<td><a onclick="kbPopupSC()"><img class="knowledge" title="Search Knowledge" src="images/icons/knowledge.gifx" height="16" border="0" width="16"></a></td');
$('status.' + field.id).up('td').setAttribute('colSpan', '3');
//Add an 'onBlur' event to search KB from 'short_description' field
Event.observe(field, 'blur', function() {
//Only search if there is a value
if(g_form.getValue('short_description') != ''){
//Only pop the search one time
if(kbPopCount < maxKBPop){
kbPopCount++;
kbPopupSC();
}
}
});
}
function kbPopupSC() {
var shortElement = $(g_form.getControl('short_description').id);
var searchText = shortElement.value;
var url = 'kb_find.do?sysparm_search=' + encodeURIComponent(searchText);
url += "&sysparm_operator=IR_AND_OR_QUERY";
popupOpenStandard(url, "kb2task");
}
This is a very interesting concept. We are looking at implementing SN this year, so I’m still very new to the SN abilities. Can SN support usage tracking on the KB overall and/or the individual articles?
You can. I actually developed some functionality to do this while I was at ServiceNow. The features I created are now part of the KCS plugin in the product. There’s a table named ‘kb_use’ that tracks usage when a user clicks the ‘Attach to Incident’ button on a knowledge article when the article is brought up from an Incident search.
This is the exact functionality we’ve been looking for. Unfortunately I added this client script (incident table, onLoad) in our test instance and it’s not popping the KB search. We have not modified the name of the short_description field or the standard KB search icon. Any suggestions?
You might check to see if you’ve got a popup blocker blocking something. You can also try it on a demo instance and send me the URL if you can reproduce it there.
Thanks for the prompt help. I added this client script to our dev instance which is basically a demo instance of SN and it is working as expected. I’m not sure how much help you can provide at this point, as it appears some of our customizations may be the reason why it’s not working in our test instance. Any other suggestions are appreciated.
It’s most likely caused by another client script or UI policy that is failing. Best advice I can give is to take a look at the error console in your browser and see if there’s an issue with something. If you’re at K12 I’d be happy to meet in person and see if we can figure it out together.
Got it working in test environment! Thanks for the help. One last question: I noticed it sorts by number of views by default. Any way you could have it sort by relevancy by default instead?
Sure. This is controlled by a system property. Check out the wiki for details.
http://wiki.service-now.com/index.php?title=Administering_Knowledge_Base_Search#Changing_the_Default_Sort_Order
One final question… Is there a way we can add some text to the pop-up? Something to the effect of “I have used the words you entered in the short description field to suggest the following knowledge base articles. If you do not find the answer to the issue you are reporting you can close this window and proceed with the incident submission.”
It’s possible, but it would be a fairly complex UI script or UI page modification to do that. You could do a standard javascript alert box in the script I’ve given. Not as user friendly, but much simpler.
Thank you for these client scripts. I was able to apply the first client script to our incident and it is working, but when I applied the other client script to our record producer it did not which I am not surprised since I am not that familiar with record procdures. I applied it to the actual item (Report an Incident) is that correc?
The client script for a catalog item should be an ‘onLoad’ script and can be applied against the item or an associated variable set. If I were to guess what the problem is it’s probably another client script that is causing the new one to fail, or your short description variable isn’t named ‘short_description’. If you can set something up in demo to reproduce and send me a link I can take a look there.
This is a very interesting approach. And also an elegant one because it does not involve too much coding. We had a similar requirement last year, and unfortunately this post was not available at that time. So we had to develop something ourselves. Eventually we came up with what we call a “dynamic KB search” because it works in an as-you-type manner.
As the user keys in the Short Description, a client script calls a script include that searches the knowledge base in the background and outputs the results back to the client script. The client script then displays search results inside a UI formatter that we placed just below the Short Description field.
I love the sound of the approach you took. I think something like that is ideal for a lot of people, but it is much more complex. I’d love to take a look at what you did if you have some code or an update set to share.
I am afraid I cannot share the code due to the corporate policy but you can take a look at the screenshot I uploaded here:
http://v-savitsky.narod.ru/dynamic_kb_search.png
The only initial requirement was to ensure a KB search is performed every time an incident is registered by the service desk. But as we worked on the code, we decided to add some more features:
1. Preview of articles by hovering over Info icon on the left
2. Copying the permalink by right-clicking the article title
3. Narrowing down the search scope by clicking on Topic, Category, Business Service, or Configuration Item
4. Articles meant for business users are marked with a green tick icon
5. Articles marked for review have a red flag beside the title indicating that they should be used with caution
6. Articles related to problem records are marked with a yellow triangle, the toolip containing PRB number and status
All of these (as well as the colors and the number of articles to display) are configured as system properties, so we can easily switch them on/off one by one if required.
Of course our solution still needs some polishing but even the way it is now it saves our service desk agents quite a lot of time.
Slava – Great post. Did you write the script include yourself or were you calling one of the existing Knowledge script includes? This will be very handy for our Service Desk.
Regarding your note about the Berlin release… I think it should work fine if you use popupOpenStandard instead of kbPopup in a similar way to what you do for Service Catalog forms.
Slava, your idea to use popupOpenStandard worked well. I did have to modify it a bit to work by putting this inside the popupOpenStandard:
“…sysparm_search=”+g_form.getValue(‘short_description’)+”…”
Hello Mark, you could create a custom function and add it to the end of the onload script and then call it instead of kbPopup. I’ve added the line sysparm_kb_search_table to what kbPopup used to do as I can see that is what is done in Berlin (instance name/scripts/elements/element_attribute_knowledge.jsx). In Berlin it looks like encodeURIComponent is used instead of encodeURI so that could be changed in the customKbPopup too.
self.fillField = me;
var shortElement = gel(me);
var searchText = shortElement.value;
var url = 'kb_find.do?sysparm_search=' + encodeURI(searchText);
url += "&sysparm_nameofstack=kbpop";
url += "&sysparm_kb_search_table=" + g_form.getTableName();
url += "&sysparm_operator=IR_AND_OR_QUERY";
popupOpenStandard(url, "kb2task");
}
YES!!! Thanks for the assist Chris! I just updated the code above so that this works from standard forms again using your workaround.
Hi Mark, this is a great feature and I’ve been looking at implementing it in our instance. One snag we have found, however, is that to be able to use the “Attach To Incident” button, the record needs to have been saved first. The problem here is that we’d like the immediacy of being to raise Incidents and save them as First-Time fix in one go, and of course having to save Incident first before attaching Knowledge hinders this. This behavior is understandable from a database perspective, however, as the Incident needs to be saved to be able to build a relationship to it. Have you been able to find a way around this?
Hey Adam, I actually haven’t found a way around that. You may need to contact ServiceNow support on that one.
Hi Mark,
Thanks for the solution. This is exactly what I have been looking for. There is something though I was wondering if it could be done. The Search pops up in a new window. Can the search results be displayed in the same page ?
The search results can be displayed in the same page, but the solution to do that is much more complex, and accomplished in a completely different way. Crossfuze Solutions does that in their Knowledge Turnkey solution and it works very well. You can take a look at the Knowledge product here and request a demo if you like.
http://www.crossfuze.com/solutions/turnkey-solutions
It worked like a charm! Thanks for sharing.
@pattipdx
I recently came across same situation, i used below script
if (isLoading || newValue == '') {
return;
}
customKBPopup(newValue.toString());
}
function customKBPopup(searchText) {
var url = 'kb_find.do?sysparm_search=' + encodeURI(searchText);
url += "&sysparm_nameofstack=kbpop";
url += "&sysparm_kb_search_table=" + g_form.getTableName();
url += "&sysparm_operator=IR_AND_OR_QUERY";
popupOpenStandard(url, 'kb2task');
}