- 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 01:36 PM
Try this - assuming 'Group 1' is replaced with the group sys_id.
if(gs.getUser().isMemberOf('Group 1')){
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2021 01:46 PM
Still not pulling in the information from the "If statement".
I also tried using u.addQuery to see if that was it.
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.getUser().isMemberOf('15f42a071XXXXX10b0fc6579bc4bcbfc')){
u.addQuery('u_project_1', '937100bc1XXXXX0b0fc6579bc4bcb31');
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2021 01:50 PM
Shouldn't the following:
var gr = u.addQuery(current.addQuery('caller_id', u).addOrCondition('u_project_1', getMyGroups()));
be
var gr = current.addQuery('caller_id', u).addOrCondition('u_project_1', "IN" , groups.join() );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2021 02:37 PM
When I try that I only get two records. Down from 76. I should have about 80.