Query Business Rule on kb_knowledge

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2022 02:54 PM
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);
- Labels:
-
Knowledge Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2022 06:37 PM
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');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2022 07:17 PM
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
Thanks
Anil Lande