Before Business Rule for Knowledge Articles
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2018 11:37 AM
I'm attempting to edit the script from this article but it's not working.: https://community.servicenow.com/community?id=community_blog&sys_id=264e66addbd0dbc01dcaf3231f96196c
I'd like to limit access based on a different field on our user records.
Field on my Knowledge Articles:
Field on the User Records:
The Business Rule is a before query business rule. The script is below.
// customer would have added a field called 'u_role'
// (instead of checking an article list)
// and each article might have this field that can be checked
// against the user's role
//
// Exceptions: users with role 'admin' or 'knowledge_admin' or 'knowledge_manager'
// will be able to see all article (not restricted by role)
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed
var userObj = gs.getUser();
if(!userObj.hasRole("admin") && !userObj.hasRole("knowledge_admin") && !userObj.hasRole("knowledge_manager")) {
var gr = new GlideRecord("sys_user");
gr.get(gs.getUserID());
var currentUserRole = gr.u_vsc_principal;
var q=current.addNullQuery('u_role');
q.addOrCondition('u_role', currentUserRole);
gs.print("Query restricted to role: " + currentUserRole);
}
}
- Labels:
-
Knowledge Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2018 11:47 AM
Why aren't you using an ACL instead?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2018 11:53 AM
From what I've read that can cause issues with search for version 3 KBs. So a user would see the result if they searched the KB but wouldn't be able to read the article.
https://docs.servicenow.com/bundle/kingston-servicenow-platform/page/product/knowledge-management/reference/r_MigratingKnowledgeAccess.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2018 12:07 PM
Ok. Is your gs.print working or is it failing before that? If it's failing earlier, add some more of those earlier to try to determine where it's failing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2018 12:19 PM
I'm not sure why you're not just using gs.hasRole() for these?
var userObj = gs.getUser();
if(!userObj.hasRole("admin") && !userObj.hasRole("knowledge_admin") && !userObj.hasRole("knowledge_manager")) {