- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2021 11:07 AM
On a Before Business Rule
I'm trying to filter records that:
- Were created by logged in user
- The Project field value on a record = one of the logged in users groups
- If the logged in user belongs to group 1 also include records where project field where = to 'X"
The top 3 lines work but the "if statement" does not add to the query
var u = gs.getUserID(); //Get the sys_id value of the current user
var groups = gs.getUser().getMyGroups();
var gr = u.addQuery(current.addQuery('caller_id', u).addOrCondition('u_project_1', getMyGroups()));
if (gs.User().isMemberOf('Group 1')) {
u.addOrContition('u_project_1', 'Group 2');
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2021 03:31 PM
This script running in a before Query Business Rule on the incident table will limit the results to only show those where:
- The Caller = the current user, OR
- The Project (custom reference field on sys_user_group) = one of the logged in user's groups, OR
- If the current user is a member of <group1>, then Project = <group2>
(function executeRule(current, previous /*null when async*/ ) {
var gr = current.addQuery('caller_id', gs.getUserID()).addOrCondition('u_project_1', 'IN', getMyGroups());
if(gs.getUser().isMemberOf('group1')){
gr.addOrCondition('u_project_1', 'group2');
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2021 03:31 PM
This script running in a before Query Business Rule on the incident table will limit the results to only show those where:
- The Caller = the current user, OR
- The Project (custom reference field on sys_user_group) = one of the logged in user's groups, OR
- If the current user is a member of <group1>, then Project = <group2>
(function executeRule(current, previous /*null when async*/ ) {
var gr = current.addQuery('caller_id', gs.getUserID()).addOrCondition('u_project_1', 'IN', getMyGroups());
if(gs.getUser().isMemberOf('group1')){
gr.addOrCondition('u_project_1', 'group2');
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2021 05:07 AM
Thank you Brad. This worked perfectly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2021 05:12 AM
You are welcome.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2021 03:45 PM
Why do you use BR for this? The results can be obtained by using list view easily
You could go to "My Groups Work" section and try to filter records based on your requirements which you mentioned initially
PS : If there is specific need to use BR, please ignore my post