Fix: Virtual Agent topic Search Knowledge Base "Sh... - ServiceNow Community
Mark Roethof
Tera Patron
Tera Patron

Hi there,

While working on Virtual Agent, we were looking at implementing the out-of-the-box topic Search Knowledge Base. During testing of this topic, we encounter an annoying/blocking defect. Defect being that if the search term would result in more results than the limit, the Show more option would be provided to the user. Upon selecting Show more though, the same results would be shown again to the user. The actual Show more does not work.

The issue

find_real_file.png

find_real_file.png

The investigation

While looking at the Virtual Agent Designer, it looked obvious the issue could be the Bot Response Script Output Display KB(s). This step is returning the results on the search phrase to the user.

Looking at the code of the Script Response Message of the Bot Response Script Output, I started debugging the integer vars quickly - index, limit, kbJsonObj.length - and short after noticed that the comparison in the for loop is the issue.

The fix

To keep things short. Below the full code for the fix. Code for the Script Response Message of Bot Response Script Output Display KB(s). As you can see, only small pieces have been changed.

Note: I did not beautify the code, though it could use some!

(function execute() {
      var limit = parseInt(vaVars.limit);

      var kbJsonObj = JSON.parse(vaVars.search_kb_json_string);

      var baseURL = gs.getProperty('glide.servlet.uri') + '/';
      vaVars.baseURL = baseURL;
      vaVars.kblinks = "";
      var index = parseInt(vaVars.index);

/* Disable code for "Show more" fix
      for (var i = index; i < limit && i + index < kbJsonObj.length; i++) {
*/
// Added code for "Show more" fix
      var end = kbJsonObj.length;
      if(index + limit < end) {
            end = index + limit;
      }

      for (var i = index; i < end; i++) {
// End added code
            var link = baseURL + gs.getProperty('sn_itsm_va.com.snc.itsm.virtualagent.portal_url') + '?id=kb_article&sys_id=' + kbJsonObj[i].id.split(':')[1];
            vaVars.kblinks += "<a href="+link+' target="_blank"><b>'+kbJsonObj[i].title+"</b></a>"+
                  "<br/>"+kbJsonObj[i].snippet.substring(0,240)+"</b>...";

/* Disable code for "Show more" fix
            if (i < limit - 1 && i + index < kbJsonObj.length - 1)
*/
// Added code for "Show more" fix
            if (i < end - 1)
//
                  vaVars.kblinks += "<br/><br/>";
      }

      return vaVars.kblinks;
})()

---

Hope that this helps some of you. Questions or ideas? Let me know!

👍
If this post helped you in any way, I would appreciate it if you hit bookmark or mark it as helpful.

Interested in more articles, blogs, videos, and Share projects on Virtual Agent I published?
Virtual Agent


Kind regards,
Mark

---

LinkedIn

Comments
Rob Sestito
Mega Sage

Hey @Mark Roethof,

Are you able to help towards a virtual agent issue I am having here Displaying user selected KA using Virtual Agent.

I have been trying to use OOTB code to try and display a KA from virtual agent. I have tried from both Preview after building the conversation and also NOW mobile app. If I use the OOTB HTML Bot Response:

<html>
    <body>
    {{vaVars.kblinks;}}
    </body>
</html>

I am shown KAs based on my selection - but if I click on the links provided, nothing is displayed since we currently have no SN Portal up (it's a project about to start).

If I use Script Output Bot Response from what you can see from my post, the conversation throws up an error message: "I'm having technical issues and won't be able to continue this conversation. Please stand by while I connect you to a live agent"

Is there a way/code - that can be used to get around this while we have no standing portal?

Appreciate your help if you are able!

Thanks,

-Rob

mrafi
Giga Contributor

Hi @Mark Roethof  @Harinder Singh 

Can we increase the limit of knowledge article count resulting in the knowledge base search in virtual agent?

I can see that there is a script variable LIMIT, which has been set as 3 OOB, but even if i increase it to more than 3, its resulting only maximum 3 results.

THanks

Rafi

Leri Andrews
Tera Guru

@Mark Roethof Hi

Unfortunately knowledge search on our Virtual Agent returns 'relevant' articles in every language where the search term is common (e.g. a user may search Microsoft Outlook even if their language is not English because that is what the system is named). 

For English users this means an article in Japanese might be at the top of the list because it mentions the word 3 more times - which makes it seem as if the agent is broken. How can we bring back articles in their preferred language first?

Thanks

Leri

 

Tushar Bhakre
Tera Contributor

This is fantastic blog and all your other blogs as well. I do follow your articles but most cases I was not logged in to bookmark. 

Thank you for sharing all these..

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Have a look at the Contextual Search.

Contextual Search > Search Contexts
Out-of-the-box ITSM VA Knowledge Search is used
Open the Recourse Configuration (on the Related Lists), out-of-the-box this is Knowledge
Update the condition on the Related List Search Resource Context Properties
find_real_file.png

For example to Test, I just added ^language=nl for dutch, immediately works.

kb_knowledge_base=dfc19531bf2021003f07e2c1ac0739ab^language=nl

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

Ryax
Tera Expert

Hi Mrafi,

 

Did you find out the answer to this? We would like to do the same and I thought it would be as simple as changing the 'limit' variable, but it does not seem to change anything.

 

Rich

Mark Roethof
Tera Patron
Tera Patron
Ryax
Tera Expert

Thanks for such a quick response Mark, that makes sense - will just have to make use of the 'show more' options 🙂

amnew
Tera Contributor

Hello Mark,

 

How we achieve the same in Paris release please help me on this i need exact same outcome.

 

please let me know your thoughts.

 

sharepointau
Mega Guru

@Mark Roethof - These are great articles!

We are interested in the same. We are just getting into Virtual Agent and love the features we are able to offer. However, we are struggling with how to replicate the "Show More," "Show Previous," etc menu that was provided by the Knowledge Search topic. 

How can we regain those options by updating the Contextual Search Topic Block? 

The need it great for our users to be able to see more of the results via VA due to the high usage in Teams.

Alex87
Tera Contributor

Hi,

is there anywhere, where the whole setup is being explained. Im looking to implement this search but looking for ways how to setup this in the flow. 

thank you for reply

 

satyendrakgupta
Giga Guru

Hi Marc,

Is this still available? Do we need to enable a particular plugin for it? We are on Quebec.

satyendrakgupta
Giga Guru

I came to know that the OOTB "Search Knowledge Base" topics are gone post-Paris and instead the Search Knowledge Base topic conversation uses the Contextual Search reusable topic block.

In my case, this was not working because the Setup topic was set as 'Fallback Topic.' for the Setup topic type: Fallback. It started working as soon as I updated the value to "Search Fallback Topic.".

[Collaboration > Virtual Agent > Custom Greetings and Setup > Setup Topics]

ITSM Virtual Agent

Now if a user utterance doesn't match an existing topic the KB search automatically happens, which is awesome and better than saying 'Search a Knowledge Base' 🙂

find_real_file.png

Harsha M V
Tera Contributor

Hi @Mark Roethof ,

I want to implement same type of logic for displaying catalog items.
I want to use this coding in

I have queried the sc_cat_item and have got the result as below

[{"name":"Standard Laptop","sysid":"04b7e94b4f7b4200086eeed18110c7fd","short_description":"Lenovo - Carbon x1"},{"name":"Development Laptop (PC)","sysid":"3cecd2350a0a0a6a013a3a35a5e41c07","short_description":"Dell XPS 13"},{"name":"Developer Laptop (Mac)","sysid":"774906834fbb4200086eeed18110c737","short_description":"Macbook Pro"},{"name":"Sales Laptop","sysid":"e212a942c0a80165008313c59764eea1","short_description":"Acer Aspire NX"}]

My output should be like below where Standard Laptop is display name and link also to that catalog item.
How to achieve this through scripting by fetching the name,sys_id and short description

 

Standard Laptop
Lenovo - Carbon x1

Development Laptop (PC)
Dell XPS 13"},{"name":"Developer Laptop (Mac)

 

Script:

(function execute() {
      var limit = parseInt(vaVars.limit);
      var index = parseInt(vaVars.index);
      
      var catJsonObj = JSON.stringify(JSON.parse(vaVars.search_result_json_string));
      gs.info("CatJsonObj value display check==="+catJsonObj);

      var baseURL = gs.getProperty('glide.servlet.uri');
      vaVars.baseURL = baseURL;
      gs.log("BASE URL=="+vaVars.baseURL);
      vaVars.cataloglinks = "";
      
      var end = catJsonObj.length;
      gs.log("End Value of catJsonObj=="+end);

      for (var i = index; i < end; i++) {
            var link = baseURL + gs.getProperty('sn_itsm_va.com.snc.itsm.virtualagent.portal_url') + '?id=sc_cat_item&sys_id=' + catJsonObj[i].id.split(':')[1];
            gs.log("Link check=="+link);
            vaVars.cataloglinks += "<a href="+link+' target="_blank"><b>'+catJsonObj[i].name+"</b></a>"+
                  "<br/>"+catJsonObj[i].short_description+"</b>...";
            gs.log("Catalog Link display=="+vaVars.cataloglinks);
            
      }

      return vaVars.cataloglinks;
})()

talk2aarav
Tera Contributor

Hi @Mark Roethof .

 

As you said the Articles are reflecting in the VA chat based on the condition in the Contextual search and if we click on Condition, we have Value(Value filed) and then we need to provide the Embedded Query here in order to reflect articles in the VA chat. 

I gave random Embedded Query and it worked fine but in my case we need to have the articles visibility based on CanRead condition for which i am not able to write Embedded Query. Any suggestion here.

And we can write in the script include but the Value filed is not recognizing (Accepting) Script include.

 

Please suggest.

 

Thanks & Regards

Naveen 

LexinZ
Tera Contributor

thank u Mark . And I want to know how to create flow like this , because  I used OOTB topic block but I don't know how to  show the result

 

Version history
Last update:
‎06-18-2019 11:58 AM
Updated by: