After working on Virtual Agent for a long time now we have realized it is a great plugin and we want to share this knowledge and lessons we learnt during all this time to ease your work. we’ll guide you through Virtual Agent Best Practices, Tips and Tricks and will go through the docs with a more simple language.

If you had ever visited this page on ServiceNow Docs, you as well might have seen this picture :

Have a look at Knowledge results shown in the above screenshot. It contains Article Numbers. But How the results are actually displayed using Virtual Agent? Have a look at below screenshot from a OOTB Topic ‘Search Knowledge Base’ (Provided with ‘ITSM Virtual Agent Conversations’ Plugin) :

Yup. There are no article numbers when used OOTB search.

We had the requirement to make our knowledge search like one shown in the above screenshot. So are you ready to see how did we achieve it?

Step 1) Search for the existing OOTB Topic and Open It.

2) Click ‘Duplicate’.

3) Give it a unique name and click ‘Save’.

4) Click ‘Edit Topic Flow’ in newly created Topic Properties Page.

5) In the designer canvas, locate the bot response ‘Display KB(s)’ that display’s knowledge results.

6) Open ‘Link List Value Expression’ script from response properties.

7) Replace the OOTB Script with the Script given below and click ‘Save’ :

(function execute(header) {
    var groupedLinksOutMsg = new sn_cs.GroupedPartsOutMsg();
    groupedLinksOutMsg.setHeader(header);
    var limit = parseInt(vaVars.limit);
    var searchJsonObj = JSON.parse(vaVars.search_kb_json_string);
    var index = parseInt(vaVars.index);
    var linkBuilder = new global.cxs_SearchResultLinkBuilder();
    test = 'OK. Before creating your incident, here are some KB articles that may help.';
    test += '';
    for (var i = index; i < index + limit && i < searchJsonObj.length; i++) {
        var link = linkBuilder.build(searchJsonObj[i], vaInputs.portal);
        var articleLink = link.link;
        var articleNumber = articleLink.match(/KB\d{7}/);
        test += '';
        }
    test += '

< table style=”text-align: left;” >
< tbody >
< tr >
< td colspan=”2″>< /td >
< /tr >
< tr >
< th style=”width: 30%;”>KB Number< /th >
< th >Short Description< /th >
< /tr >
< tr >
< td >< a href = “‘+ articleLink + ‘ ” >’+ articleNumber + ‘< /td >
< td >’ + link.label + ‘< / td >
< / tr >
< / tbody >
< / table >
‘;
return test;
})(header)

8) Locate the Bot Response ‘Found Result Message’ and delete it.

Hurry, You have created the Custom BA Knowledge Results Response which looks like as mentioned in the Docs.

If you’ll compare it with OOTB script you’ll realize the only change made was using HTML tags and RegEx.