Global Search - Conditions on KB articles not working

Justin Lee2
Tera Guru

I have a requirement to exclude all Knowledge in a particular Knowledge Base from the Global Search.

Users still need access to the articles in that KB - they just don't want them to show up in the Global Search.

 

I have added the condition (Knowledge Base != [the knowledge base]) to both of the active Search Sources (sys_search_source) for Knowledge.

 

However, when I add a new article in the knowledge base, it still immediately shows up in the global search.  In fact, even if I disable the Search Sources for Knowledge, new and existing articles continue to show up in global search.

 

How can this be achieved?  Is there somewhere else I need to add the condition?

1 ACCEPTED SOLUTION

Tanushree Maiti
Tera Patron

Hi @Justin Lee2 

 

Apply this KB steps once for Knowledgebase and check 

KB0677487 How to exclude certain article categories from searches performed in the Knowledge homepag... 

 

https://www.servicenow.com/community/itsm-forum/how-to-exclude-certain-articles-from-knowledge-searc...

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

View solution in original post

3 REPLIES 3

Justin Lee2
Tera Guru

FYI - I also added the condition to the "Text Search Table" record for Knowledge.  Still has no effect.

Tanushree Maiti
Tera Patron

Hi @Justin Lee2 

 

Apply this KB steps once for Knowledgebase and check 

KB0677487 How to exclude certain article categories from searches performed in the Knowledge homepag... 

 

https://www.servicenow.com/community/itsm-forum/how-to-exclude-certain-articles-from-knowledge-searc...

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

Thanks Tanushree!  Those links got me in the right direction.

 

For anyone with similar requirements, instead of adding to the existing business rule, I had to create a new query business rule, and call the below function in the "Conditions" field.  If you do the check in the actual script, it will work, but it will show an error message whenever you retrieve an article in script. This is because gs.action.getGlideURI() throws a java error in that scenario, and try/catch does not avoid it. However, in the conditions filed of the business rule, it does not show the error.

 

Additionally, there are a few URLs that may be called by global search.  I'd also point out that this is probably a fragile solution, as ServiceNow may change the url called by global search at any time, and this would break.  Additionally, there may be places other than global search that use these URLs to retrieve knowledge.  So if anyone uses this solution, you may want to regression test with each SN release.

 

shouldApplyGlobalSearchFilter: function() {
        if (!gs.getSession().isInteractive())
            return false;
        try {
            var url = gs.action.getGlideURI().toString();
            if (url.indexOf("api/now/graphql?api=api") > -1)
                return true;
            if (url.indexOf("api/now/v1/batch?api=api") > -1)
                return true;
            if (url.indexOf("api/now/uxf/databroker/exec?api=api") > -1)
                return true;
           
            return false;
        } catch (ex) {
            return false;
        }
    },