Having issue with Query business rule on Knowledge Article table

Musab Rasheed
Tera Sage
Tera Sage

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);

Please hit like and mark my response as correct if that helps
Regards,
Musab
1 ACCEPTED SOLUTION

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);

View solution in original post

13 REPLIES 13

Maik Skoddow
Tera Patron
Tera Patron

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

Hello @Maik Skoddow : Suppose HR agents goes to KB article table to see all the articles visible to him then he sees 'security constraints' message like below. This is happening due to ACL but client wants to implement something which will eliminate such message and instead show articles which agents can see. For this I have written query BR in which I'm trying to check 'can read' and 'cannot read' to display articles to agents. Let me know if you need more info.

 

find_real_file.png

 

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);

 

 

Please hit like and mark my response as correct if that helps
Regards,
Musab

Hi

this message is based of any underlying ACLs . This is not a matter of user criteria!

Kind regards
Maik

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

Please hit like and mark my response as correct if that helps
Regards,
Musab