Query Business Rule on kb_knowledge

Laura_Diggs
Giga Guru

We're working on adding a query business rule to kb_knowledge to get rid of the 'rows removed by security constraints' message since it's causing some confusing behavior to our users who manage a subset of our knowledge bases. I've added the below script for my business rule, but I don't really love it and I'm concerned that it's not going to scale well down the road. Is there a better way to accomplish this?

 

 

(function executeRule(current, previous /*null when async*/) {

var kbs = new GlideRecordSecure('kb_knowledge');
kbs.query();

var kbList = '';
while (kbs.next()) {
kbList += (kbList == '') ? kbs.sys_id : ',' + kbs.sys_id;
}

current.addQuery('sys_id', 'IN', kbList);

})(current, previous);
2 REPLIES 2

Tony Chatfield1
Kilo Patron

Hi, normally I would look at mirroring the constraint(s) set by the ACL IE if it has a script, or role restrictions try and deliver the same basic context in your query via use of user criteria for can read/cannot read or using roles to provide a result that can be queried via data subsets\values rather than individual records.

Otherwise if you can filter kbs on values that are not unique, you can at least reduce the number of sys_id's that you will need to return IE
kbs.addEncodedQuery('active=true^workflow_state=published');

 

Anil Lande
Kilo Patron

Hi,

One thing I noticed here is you are putting it in recursion.

If this BR is on "kn_knowledge" table then you querying same table in before query business rule will again call Before Query and so on.

 

I would advice not to write GlideRecord query (atleast for same table) in before query table. It will impact the performance.

As suggested by Tony try to adapt the criteria used in ACL's and apply logic in same way to filter records. You can take a look at existing BR's to understand the functionality of before query BR.

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande