How to define Before/Query Business Rule to give users read access to the table based on conditions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2022 01:37 AM
I have the requirements to allow users to access (read) a table based on the following conditions.
1) Users can read all the records which "Confidential" is FALSE.
2) For records with "Confidential" is TRUE, users can read them only if the logged in user's Company is same as "Company [u_company]" field value.
I created the Before Query Business Rule below, but the result is that users can read all the records which "Company" is same as logged in user's one, regardless of the "Confidential" check... Could someone please advise me on how to meet the requirements using BR?
(function executeRule(current, previous /*null when async*/) {
current.addQuery('u_company', gs.getUser().getCompanyID());
})(current, previous);
Best Regards,
Aki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2022 01:59 AM
Hi @Aki18
Can you try below code and see what you are getting in info message:-
(function executeRule(current, previous /*null when async*/) {
current.addQuery('u_company', gs.getUser().getCompanyID());
gs.addInfoMessage("Query:" + current.getEncodedQuery());
})(current, previous);
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2022 09:59 AM
Hi @Gunjan Kiratkar ,
Thank you for your reply. Here is the log message displayed when accessed the table list: