How to get sys_id of a knowledge base programmatically from Virtual Agent

Timothy J
Tera Contributor

Hello, community members.

In one of my Virtual Agent's contextual search, I am using VAGlobalContextualSearchUtil().  The part of Virtual Agent Script is

(function execute() {
var contextualSearch = new global.VAGlobalContextualSearchUtil();
var response = contextualSearch.search(
vaInputs.context.getDisplayValue(), vaInputs.query, vaInputs.kb_knowledge_base

I am able to search single knowledge base named "Test Cases" by putting in sys_id of "Test Cases" knowledge base in place of vaInputs.kb_knowledge_base.  What would be the best way to get the sys_id of the knowledge base programmatically?  

 

Thank you for all your help

2 REPLIES 2

Chris D
Kilo Sage
Kilo Sage

This may depend on how many KBs you have (would be annoying for >10 and downright unpleasant for >20), but if you're looking to get the KB from the user - i.e. "What Knowledge Base would you like to search?" - just do that as a reference input on the Knowledge Base table (kb_knowledge_base), active = true plus any other filter.

Then just pass that vaInput (the sys_id of that KB) to your search and you got it.

If you don't want the user input to determine the KB, then I'm not quite sure what you're getting at but you can also do a record lookup on the same table and similarly vaInputs.record_lookup would be the sys_id - nothing strictly programmatic needed based off what you've said so far.

Mark Roethof
Tera Patron
Tera Patron

Hi there,

"What would be the best way to get the sys_id of the knowledge base programmatically?"

You could just add a GlideRecord query, and query for the Knowledge Base name. Few seconds of work, shouldn't be that difficult.

Though obviously be aware that the name is not unique, perhaps a typo, etc..

So where is the name coming from? Is it something one would type manually as VA input? Or from somewhere else?

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

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

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn