Fix: Virtual Agent topic Search Knowledge Base "Show more"
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
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
---
https://www.servicenow.com/community/virtual-agent-nlu-articles/fix-virtual-agent-topic-search-knowledge-base-quot-show-more/ta-p/2301899
