
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2022 06:58 AM
Hello Experts,
I have a requirement to show knowledge articles to users who are satisfying can read and cannot read criteria , I'm doing this to get rid of 'Security constraints' message which is annoying to customers, I have written query business rule to query can read and cannot read fields but it is not working 100%. kindly help to identify issue here. Below is the code.
I have considered below scenarios to write this BR.
1) Can Read , Cannot read - Empty.
2) Can Read - Empty , Cannot read - Not empty.
3) Can read - Not empty , Cannot read - Empty.
4) Can Read - Not empty , Cannot read - Not empty.
(function executeRule(current, previous /*null when async*/ ) {
var allUserCriteria = SNC.UserCriteriaLoader.getAllUserCriteria();
//Can read not empty
var canReadQuery = allUserCriteria.join('^ORcan_read_user_criteriaLIKE');
canReadQuery = 'can_read_user_criteriaLIKE' + canReadQuery;
//Cannot read not empty
var cann = allUserCriteria.join('^cannot_read_user_criteriaNOT LIKE');
cann = 'cannot_read_user_criteriaNOT LIKE' + cann;
var canempty = 'can_read_user_criteriaISEMPTY';
var cannottempty = 'can_read_user_criteriaISNOTEMPTY';
var cannotempty = 'cannot_read_user_criteriaISEMPTY';
var cannotnotempty = 'cannot_read_user_criteriaISNOTEMPTY';
var gr1 = canempty + '^' + cannotempty;
var gr2 = canempty + '^' + cannotnotempty + '^' + cann;
var gr3 = cannotempty + '^' + cannottempty + '^' + canReadQuery;
var gr4 = cannottempty + '^' + cannotnotempty + '^' + canReadQuery + '^' + cann;
var err = gr1 + '^NQ' + gr2 + '^NQ' + gr3 + '^NQ' + gr4;
current.addEncodedQuery(err);
})(current, previous);
Regards,
Musab
Solved! Go to Solution.
- Labels:
-
Agent Workspace
-
Knowledge Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2022 09:56 AM
Disclaimer: An ACL is definitely the recommended way to do this! The method below could be very inefficient depending on the number of records in your kb_knowledge table.
If I'm understanding correctly, you just need to query based on the sys_ids in the kb_knowledge table that the current user can read, right? You should be able to leverage the GlideRecord.canRead() function here. Get all articles, then iterate them and return the sys_ids of the ones where kb.canRead() is true.
(function executeRule(current, previous) {
var allowedIds = [];
var kb = new GlideRecord('kb_knowledge');
kb.query();
while (kb.next()) {
if (kb.canRead()) {
allowedIds.push(kb.getUniqueValue());
}
}
current.addEncodedQuery('sys_idIN' + allowedIds);
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2022 08:38 AM
Hi
sorry, but I have no idea what you are doing.
Could you please explain your issue better (details, screenshots) before asking for a solution which makes no sense to me?
Kind regards
Maik

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2022 08:56 AM
Hello
BBR :
I have considered below scenarios to write this BR.
1) Can Read , Cannot read - Empty.
2) Can Read - Empty , Cannot read - Not empty.
3) Can read - Not empty , Cannot read - Empty.
4) Can Read - Not empty , Cannot read - Not empty.
(function executeRule(current, previous /*null when async*/ ) {
var allUserCriteria = SNC.UserCriteriaLoader.getAllUserCriteria();
//Can read not empty
var canReadQuery = allUserCriteria.join('^ORcan_read_user_criteriaLIKE');
canReadQuery = 'can_read_user_criteriaLIKE' + canReadQuery;
//Cannot read not empty
var cann = allUserCriteria.join('^cannot_read_user_criteriaNOT LIKE');
cann = 'cannot_read_user_criteriaNOT LIKE' + cann;
var canempty = 'can_read_user_criteriaISEMPTY';
var cannottempty = 'can_read_user_criteriaISNOTEMPTY';
var cannotempty = 'cannot_read_user_criteriaISEMPTY';
var cannotnotempty = 'cannot_read_user_criteriaISNOTEMPTY';
var gr1 = canempty + '^' + cannotempty;
var gr2 = canempty + '^' + cannotnotempty + '^' + cann;
var gr3 = cannotempty + '^' + cannottempty + '^' + canReadQuery;
var gr4 = cannottempty + '^' + cannotnotempty + '^' + canReadQuery + '^' + cann;
var err = gr1 + '^NQ' + gr2 + '^NQ' + gr3 + '^NQ' + gr4;
current.addEncodedQuery(err);
})(current, previous);
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2022 08:58 AM
Hi
this message is based of any underlying ACLs . This is not a matter of user criteria!
Kind regards
Maik

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2022 09:03 AM
Yes I know but we can remove that message based on query BR and the query I have added in BR is not working perfectly , I tested few scenarios It is working fine but failing for few. I have seen people using Query BR logic to get rid of ACL message on Incident table but no one has tried on KB table I guess
Regards,
Musab