easy way to add a couple knowledge bases to your service portal search?

wbwb
Tera Expert

Is there really still no way to add additional knowledge bases to your service portal's search feature?  Seems like this should be a simple configuration but everything I'm pulling up in my research suggests I have to customize this.  We're using Jakarta.

1 ACCEPTED SOLUTION

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

This query is going against the database so any exceptions need to be "spelled" out in the code.  You could add a "dot-walk" query around the same lines you were editing to filter only on active knowledgebases, but dot-walk queries cause table scans since it has to loop through all articles looking for ones where the knowledgebase is active.  Depending on how many articles you have this could get expensive and cause performance issues.

 

How many KB's are you wanting to search?  All of them or do you have a limited set?  There may be a better way to gather the list of active knowledgebases to pass into this query.

Otherwise, a better You can add a check within the loop to see if the knowledgebase is active and if not continue past this article.  So you would edit lines 15-16 in the script pasted above with:

        // Does user have permission to see this item?  Is the knowledgebase active?
        if (!$sp.canReadRecord("kb_knowledge", kb.getUniqueValue()) || !kb.kb_knowledge_base.active)
            continue;

 

Please mark this post or any as helpful or the correct answer to your question so others viewing this thread can benefit.

View solution in original post

9 REPLIES 9

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Replace line 7 with:

var kbQuery = kb.addQuery('kb_knowledge_base', $sp.getValue('kb_knowledge_base')).addOrCondition('kb_knowledge_base', 'KB-2-SYSID').addOrCondition('kb_knowledge_base', 'KB-3-SYSID');

You with OR conditions you have to establish that in a variable.  Just to be clear, KB1 will be defined in the Service Portal (sp_portal) record and then you put in the SysIDs of the other kb_knowledge_base records you also want to search.

wbwb
Tera Expert

I initially left out "var kbQuery = " and tested and it searches across all 3 of my KB's now.  I put it in "var kbQuery = " and get the same behavior.  I'll leave it in though if you recommend it.

I do think it's strange that even if a knowledge base is inactive it'll still be searched.  I guess this query and search results doesn't take that into consideration.  Is it easy to update this query to make sure knowledge bases are active so it leaves out inactive ones?

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

This query is going against the database so any exceptions need to be "spelled" out in the code.  You could add a "dot-walk" query around the same lines you were editing to filter only on active knowledgebases, but dot-walk queries cause table scans since it has to loop through all articles looking for ones where the knowledgebase is active.  Depending on how many articles you have this could get expensive and cause performance issues.

 

How many KB's are you wanting to search?  All of them or do you have a limited set?  There may be a better way to gather the list of active knowledgebases to pass into this query.

Otherwise, a better You can add a check within the loop to see if the knowledgebase is active and if not continue past this article.  So you would edit lines 15-16 in the script pasted above with:

        // Does user have permission to see this item?  Is the knowledgebase active?
        if (!$sp.canReadRecord("kb_knowledge", kb.getUniqueValue()) || !kb.kb_knowledge_base.active)
            continue;

 

Please mark this post or any as helpful or the correct answer to your question so others viewing this thread can benefit.

wbwb
Tera Expert

Great info.  I really appreciate all the help on this one!!!

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

You are welcome, happy to help.