Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Access to the Unpublished Knowledge Article only to the KB owner or to users having knowledge_admin role

abhinandanparhi
Kilo Expert

Hi Community,

Please help with the query.

I want to restrict the unpublished knowledge articles to  the knowledge owner or to users having knowledge_admin role. However, i am not able to achieve this with the following script. I modified the script a bit for both ACL's and QueryBR but with no access.

Before Query BR on kb_knowledge table with condition as Workflow is not Published.

var kbsysid = current.sys_id;
var kbknowledgebase = current.getDisplayValue(kbsysid);
var knowledgebase = new GlideRecord('kb_knowledge_base');
knowledgebase.addQuery('title',kbknowledgebase);
knowledgebase.query();
if(knowledgebase.next()){
var kbowner = knowledgebase.owner;

if((gs.getUser().getID() == kbowner) )
return true;                                       // answer = current.canRead() for ACL
else
return false;
}

 

6 REPLIES 6

Hi Sharjeel,

Thanks for your reply.

This is working fine for unpublished articles which is as per the requirement.However , no one is able to view published articles now. No records are found for published articles for owners or admins.

Thanks,

Abhinandan

@abhinandanparhi22, Glad to be of Help!

Please be kind to mark the appropriate response as CORRECT so that others can referenced that and get benefited by that.

Happy Coding!

 

Thanks & Regards,

Sharjeel

Regards,
Muhammad