Query Business Rule Based on List View

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2018 11:21 AM
Hi I'm trying to accomplish running a single Query Business Rule which performs a different set of queries depending on what the list view is. I can get it to work but I'm running into an issue where certain records which are in the active state but aren't created by that user can't be seen. The record is within the list view but on click it throws a "Record Not Found" message on a blank screen. Any ideas of why this would occur?
Here's my code:
if(gs.hasRole('role1') && !gs.hasRole('role2')) {
if(view_name == "" /* This is for the default view */ || view_name == 'view1') {
var incentiveQuery = current.addQuery('sys_created_by', gs.getUserName());
incentiveQuery.addOrCondition('state', '3');
incentiveQuery.addOrCondition('u_owner1', gs.getUser());
incentiveQuery.addOrCondition('u_owner2', gs.getUser());
incentiveQuery.addOrCondition('sys_id', 'IN', approversArray);
current.addQuery('u_ype', '!=', 'badType');
}
else if(view_name != '' && view_name != 'new_vendor_view') {
var allowanceQuery = current.addQuery('sys_created_by', gs.getUserName());
allowanceQuery.addOrCondition('u_owner1', gs.getUser());
allowanceQuery.addOrCondition('sys_id', 'IN', approversArray);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2018 12:29 PM
A couple thoughts:
- Is u_ype correct? I wasn't sure if this is the actual name of the field or if there is a typo (either here or in your original code).
- For the more complicated query, you might want to add an encoded query instead of what you have there. It might help resolve any conflicts in logic it's finding.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2018 12:46 PM
u_ype was a typo but isn't the actual name of the field, I was faking them for the question haha.
The queries seem to be working, I can see all the active records even if the user didn't create them or are one of the approvers. The weird part is when you click on one of those records it tells me "record not found." This only occurs when I have the else if, checking if it's any other view. I thought maybe it was because the form view was called something different so it would then run the second query removing the ability to see the active record, but that doesn't seem to work.
Do Query Business Rules run for read privileges on forms as well?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2018 12:52 PM
My understanding is that if the user has access to the record via a read ACL, that the query business rule might further restrict their access. However, if they don't have read access for the record, I would think that the query business rule would not override that.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2018 07:32 AM
So it was my else if causing all the trouble. I ended up removing the view_name != 'view1' and changed it to if the view_name equals whatever specific view I want the query to run on, execute this code.
Thanks for your input though, I appreciate it.
Dylan