How to exclude certain articles from Knowledge search results for certain users?

qz8437
Mega Contributor

I want to exclude a subset of articles from appearing in the results for my Service Desk team, based on the value of a custom field.   We have a Document Type field that identifies whether it is intended for First Level Support Second Level Support, etc.   I don't want the First Level Support users to be slowed down by seeing Second Level Support documents in their search results.   These folks can be identified by either group membership or Role, whichever works.   What's the best way to accomplish this?

1 ACCEPTED SOLUTION

jeremy_gardner
Tera Expert

Thinking out loud (which gets dangerous)...



When you look at a list of records or enter something in search, a query string is passed server side to return your list of results.   I'm thinking that query string would look different when coming through Search than looking at list of kb_knowledge record list directly.  



If it is, what if you setup a query BR that looks at contents of current.getEncodedQuery(), and based on the search string and current user's role (or lack of a role or group), add a query to remove 2nd level documents:



    current.addQuery('document_tier', '!=', '2nd level');


View solution in original post

8 REPLIES 8

jeremy_gardner
Tera Expert

Thinking out loud (which gets dangerous)...



When you look at a list of records or enter something in search, a query string is passed server side to return your list of results.   I'm thinking that query string would look different when coming through Search than looking at list of kb_knowledge record list directly.  



If it is, what if you setup a query BR that looks at contents of current.getEncodedQuery(), and based on the search string and current user's role (or lack of a role or group), add a query to remove 2nd level documents:



    current.addQuery('document_tier', '!=', '2nd level');


Thanks for this suggestion.   I might be able to make this work.   Could be tricky.   Thanks again.


I finally got back to working on this, and your suggestion is a good solution.   I created a query business rule for the KB table with this condition:


current.getEncodedQuery().indexOf('IR_OR_QUERY=') >= 0 || current.getEncodedQuery().indexOf('IR_AND_QUERY=') >= 0 || current.getEncodedQuery().indexOf('IR_AND_OR_QUERY=') >= 0



This seems to only include the knowledge searches and not list-view filtering.   Then in the script I do this:



var gName = gs.getProperty('servicedesk.group.name');


var thisUser = gs.getUser();



if(thisUser.isMemberOf(gName)) {


    current.addQuery('u_doctype', '!=', 'Level 2 Procedure');


}



And it works!


Thanks Jeremy!   And thanks to the others that replied as well.


Michael Ritchie
ServiceNow Employee
ServiceNow Employee

I have seen similar things done in HR Case.   There HR staff often have the requirement to search the knowledge base "as the employee".   I have seen this done with a new UI Action and code similar to the following in the client (checked) script


function searchKb() {


      var caller = g_form.getValue('opened_for');    


      var searchText = g_form.getValue('short_description');


      var url = 'kb_find.do?sysparm_search=' + escape(searchText);


      url += "&sysparm_nameofstack=kbpop";


      url += "&sysparm_callerid=" + caller;


      url += "&sysparm_operator=IR_AND_OR_QUERY";


      url += "&sysparm_kb_search_table=hr_case";



      popupOpenStandard(url, "kb2task");


}


Unsure if changes were made to the out of the box kb_find UI Page though.