Is there a way to pass multiple knowledge bases to SNC.SearchRequest()?

eurban
Kilo Expert

I am wondering if anybody knows if it is possible to pass multiple knowledge base IDs to the method SNC.SearchRequest()?

The question came from a need to customize the UI Macro kb_find_query to try to search two or three knowledge bases instead of all as it does now.   I have found that searching for articles in one KB is possible, which is shown by an example using the URL parameter "sysparm_kb", but I am not able to use two or three:

https://<instance>.service-now.com/kb_find.do?sysparm_search=test&sysparm_kb=9d385017c611228701d22104cc95c371&sysparm_nameofstack=kbpop&sysparm_kb_search_table=incident&sysparm_operator=IR_AND_OR_QUERY&sysparm_order=relevancy&sysparm_domain_restore=false  

In kb_find_query, there is an object property knowledgeBase in the object searchParams.   This searchParams object is the value of the object property searchParameters that is an object property of the "query" object that is passed in as a parameter to SNC.SearchRequest(), which is passed in using JSON.

Since that is kind of a mess to follow, it could help to show that:

searchRequestObj

        --> query

                  --> searchParameters: searchParams

                            --> knowledgeBase

I reached out to ServiceNow to see if they would provide any info on SNC.SearchRequest but I don't feel their response was completely clear because they said the "system" doesn't support using multiple knowledge bases (aside from all).   It does seem to suggest that SNC.SearchRequest wasn't designed to take in more than one knowledge base, but I still thought I would ask here in case someone knows something that they didn't provide.   For reference, here is their response:

By default, the system only supports two search methods:

1) Search all knowledge bases2) Search a specific knowledge base.

There is no configurable or supported way of searching multiple knowledge bases. You are of course welcome to attempt to write your own routines to do so, but if you are unable to do this with the functions and methods available to you, there is unfortunately not a lot support can do for you. I am also forbidden from providing any insight into protected code elements like SearchRequest, unless it has a documented api, which in this case there is not one.

At this time there is no documentation that details how to achieve the functionality you're requesting. My best suggestion would be to make multiple calls to searchrequest and then collate and display those results - but apart from that high level thought my hands are tied on this one. You may want to check out the community for this question, perhaps there is someone out there who has already tackled this.

I should be able to do as the ServiceNow rep suggested, which would be to combine the results of the two responses into one response, but this isn't quite as clean as making a single query and getting a single response object back.   I did try to pass in an array of knowledge base IDs like is done for kb_category, author, and tags in kb_find_query, but that didn't seem to work in my tests.

3 REPLIES 3

a116170
Tera Contributor

For what it's worth, if you're on Knowledge v3 you can do this with a URL like the following:



$knowledge.do?query=test&sysparm_type_filter=all&sysparm_kb_ids='some sys_id of KB'&sysparm_kb_ids='some sys_id of another KB'&sysparm_order=relevancy&sysparm_domain_restore=false&sysparm_stack=no


Thanks, Chris, that is useful to know!   Unfortunately, that doesn't quite solve the problem I had because the goal was to modify the search that was being performed from an incident by clicking on the "Search Knowledge" button on the incident form (also found in CHG and PRB).   The search there uses the kb_find_query UI Macro.   I still appreciate the response though.


jab
Kilo Contributor

We have axactly the same problem/question.
We have a button (custom knowledge search) on the HR Case form.
When the button is clicked, only the HR knowledge bases should be searched for the text in the subject field.

It works fine when we use the parameter sysparm_kb in the url. But with that parameter you can only pass one knowledge base to the search.

Unfortunately the solution provided by a116170 does not work.
I've not been able to find anything about the parameter sysparm_kb_ids in the official SN documentation.

Did anybody find a solution to search on multiple (defined) knowledge bases via URL (or maybe another solution without URL)?