The CreatorCon Call for Content is officially open! Get started here.

Hide unpublished kb articles on the service portal for users

Phil4
Mega Contributor

The business has asked if it is possible to hide unpublished knowledge articles on the Service Portal for users but not affect the back end client search. The requirement is so that users have the same experience as customers do when using the portal, 

I understand the following setting within properties, but unticking this option will not allow users to search related articles within incidents etc. 

find_real_file.png

Our portal has been setup to use a Typehead Search widget with SNC.SearchRequest and from what I understand there would be no way to pass a parameter into it to only return published articles as the following seems to be the only rules that can be applied

  • knowledgeBase
  • topic
  • category
  • language
  • department

I might be looking at this from the wrong perspective so any help directing me to another way of doing this would be greatly appreciated.

1 ACCEPTED SOLUTION

Phil4
Mega Contributor

For anyone interested in knowing the outcome - I was looking at it the completely wrong way.

 

I was given a lead to look at the Service Portal -> Search Sources

In my Knowledge search source I was able to add an extra part to the encoded query -  + "^workflow_state=published".

Adding this removed the results from the search and from the categories listing but had no affect on the client side.

 

Using ACLs or User Criteria did not work 

View solution in original post

9 REPLIES 9

I was trying to pre-filter knowledge base search for employee center and finally got it working by adding to the end of:

// return built up query, stripping away leading ^
return (kbQuery.startsWith("^")) ? kbQuery.substring(1) : kbQuery;

 

So mine looked like:

// return built up query, stripping away leading ^
return (kbQuery.startsWith("^")) ? kbQuery.substring(1) : kbQuery + '^sys_updated_onRELATIVEGT@year@ago@1';



Which by default only displays articles updated a year ago or sooner. Not 100% sure if that's the best approach but it worked.

Sorry for the delay in responding.

Jesse has updated the script in the same place I did mine.

Under Service Portal -> Search Source I went into Knowledge Bases.

Around line 120 in the Data fetch script is the query that Jesse and I updated.

// return built up query, stripping away leading ^
return (kbQuery.startsWith("^"))? kbQuery.substring(1): kbQuery + 
 ^workflow_state=published";

 

Hope this helps

Hi @Phil4 

Would you mind to show the details how did you added the condition? I'm also looking for the same solution. Hope you dont mind to share. Thanks

Hi Suraya82

 

Sure, head to Service Portal -> Search Source. In the list that appears go to Knowledge Bases.

In the Data fetch script look for the comment "// return built up query, stripping away leading ^" 
for me, this was at lines 119 and 120

 

Your 'Out of the Box' code below this should read 
return (kbQuery.startsWith("^"))? kbQuery.substring(1): kbQuery

 

You can add your own requirements to the end of the code. For me and my initial question, I added + "^workflow_state=published"

 

So this is my code now.

// return built up query, stripping away leading ^
return (kbQuery.startsWith("^"))? kbQuery.substring(1): kbQuery + "^workflow_state=published";

 

I hope this explains it better.

Phil,

Thank you very much for the reply. I've tried this solution however it is not working for my case. I wanted to remove this warning message from the Portal and this message should not disappear from the backend. Do you happen to know any other solution to my issue? 

Suraya82_0-1683773984337.png

 

I've tried this solution as well but the warning disappear both in the portal and backend.

Warning message that is displayed when trying to a... - ServiceNow Community

Suraya82_1-1683774463346.png