Virtual agent, limiting KB search results

Jonathan28
Giga Contributor
Hi
I would like to limit the amount of KB search results that I get in the Virtual agent.
I have been trying to play around with the ".setlimit()" function but haven't been able to solve the problem
 
Could someone put me in the direction in what I need to do to in order to fix this?
 
 
Below is the code for displaying kb articles taken from the "Submit an incident" topic.
 
(function execute() {
var kbs = JSON.parse(vaVars.search_kb_json_string);
var helper = new ItsmVaHelper();
var baseURL = gs.getProperty('glide.servlet.uri') + '/' + gs.getProperty('sn_itsm_va.com.snc.itsm.virtualagent.portal_url');

var items = kbs.map(function(kb) {
return helper.formatKBSearchResult(baseURL, kb);
}).join('<br />');
 
var html =
'<div>' +
'<div>' + gs.getMessage('Before opening your incident, here is some information that might help you:') + '</div><br />' + items +
'</div>';
 
return html;
}
1 ACCEPTED SOLUTION

Tudor
Tera Guru

Hi Jonathan,

 

 Please take a look at the contextual search and limit the number of articles from there:

find_real_file.png

 

in the for:

for (var index=0;index<relevantSearchResults.length;index++)
{
if (relevantSearchResults[index].meta.knowledgeBaseId=='247d3944db8ae7006bf69334ca9619ca')
{
results.push(relevantSearchResults[index]);
str = JSON.stringify( results )
vaVars.kbResultCount++;
}
}
and an if condition like:
 
for (var index=0;index<relevantSearchResults.length;index++)
{
if (relevantSearchResults[index].meta.knowledgeBaseId=='247d3944db8ae7006bf69334ca9619ca')
{
results.push(relevantSearchResults[index]);
str = JSON.stringify( results )
vaVars.kbResultCount++;
}
if (index==5) // here I set the limit to 5 ... feel free to play around
break; //will stop the loop
}

View solution in original post

8 REPLIES 8

Tudor
Tera Guru

Hi Jonathan,

 

 Please take a look at the contextual search and limit the number of articles from there:

find_real_file.png

 

in the for:

for (var index=0;index<relevantSearchResults.length;index++)
{
if (relevantSearchResults[index].meta.knowledgeBaseId=='247d3944db8ae7006bf69334ca9619ca')
{
results.push(relevantSearchResults[index]);
str = JSON.stringify( results )
vaVars.kbResultCount++;
}
}
and an if condition like:
 
for (var index=0;index<relevantSearchResults.length;index++)
{
if (relevantSearchResults[index].meta.knowledgeBaseId=='247d3944db8ae7006bf69334ca9619ca')
{
results.push(relevantSearchResults[index]);
str = JSON.stringify( results )
vaVars.kbResultCount++;
}
if (index==5) // here I set the limit to 5 ... feel free to play around
break; //will stop the loop
}

Jonathan28
Giga Contributor

@THosu thank you I will try the contextual search. I will get back to you 🙂

Mark Roethof
Tera Patron
Tera Patron

Hi there,

What are you exactly willing to limit?

The results returned from certain Knowledge Bases?
The number of total results returned?

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Jonathan28
Giga Contributor

Hi,
 

@Mark I want to limit the amount of KB articles that get presented to the user. So instead of presenting 10 articles, I want to present 5 articles so that the bot window isn't filled with KB results.