- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-03-2020 06:14 AM
Hi
I want to make a scoped BR run a conditon:
Suppose the BR is on incident table, then the BR should only run when the caller in the caller_id field is a member of a particular group.
I tried the below code in the condition field
gs.getUser(current.caller_id).isMemberOf(<group name>)
But this gives false, because instead of taking the user in caller field it takes logged in user.
Any solution for this?
Note: If similar code is user in background script as below in a gliderecord: gs.getUser(gr.caller_id).isMemberOf(<group name>) It returns the expected output. |
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-04-2020 05:09 AM
HI
isMemberOf() will only work for loggedin users but as your requirement is to use the script in BR CONDITION. To achieve this you need to write a Script include and GlideRecord Group Member table and check if Caller is member of group then return true otherwise return false. Let me give you a sample.
BR CONDITION [if script include is in SAME scope]
javascript: new groupMemberUtility().member(current.caller_id);
BR CONDITION [if script include is in GLOBAL scope i.e call it by its API name]
javascript: new global.groupMemberUtility().member(current.caller_id);
SCRIPT INCLUDE
NAME - groupMemberUtility
var groupMemberUtility = Class.create(); //(auto generated)
groupMemberUtility.prototype = Object.extendsObject(AbstractAjaxProcessor, { //(auto generated)
member: function(data) {
gs.info("$$SH ---> Script include called!!! " + data);
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("user", data);
gr.setLimit(1);
gr.query();
if (gr.next())
return true;
return false;
},
});
Please mark this CORRECT & HELPFUL, if it answered your question.
Thanks & Regards,
Sharjeel
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-04-2020 02:41 AM
Hi TM,
This method works in scoped application as well. The only thing i could see is maybe its not getting the caller id that is why it didn't worked.
Can you try putting the sysid of the any caller and check whether its working fine or not:
gs.getUser().getUserByID('107af36914513200964f3eef35775a23').isMemberOf('RMA Approvers')
like this:
So Dynamic code would be: Replace the group name with your group name
gs.getUser().getUserByID(current.caller_id).isMemberOf('RMA Approvers')
Service now documentation link which says this methods work in scoped applications.
Mark helpful and correct if it help.s
Thanks,
CB

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-03-2020 06:26 AM
Hi,
gs.getUser().isMemberOf(<groupname>) is the correct syntax.
To check the isMember of in sever side, use below code
var isMbr = new GlideRecord('sys_user_grmember');
isMbr.addQuery('group='+'<groupname>'+^user='+current.caller_id);
isMbr.query();
if(isMbr.next())
return true;
else
return false;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-04-2020 12:56 AM
Hi Anirban
gs.getUser().isMemberOf(<groupname>) : This will check for the logged in user right, but should be able to do it for the user in caller field
Cannot use the GlideRecord since this has to go to condition field of BR.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-05-2020 05:26 AM
Hi,
I meant 'gs.getUser(gr.caller_id).isMemberOf(<group name>)' was wrong syntax and correct syntax would be 'gs.getUser().isMemberOf(<groupname>)'
But, to use the logic for the caller id, you need to use the piece of code that I shared.
// logic to fetch user's group
isMemberOfCustom: function(userId, grp)
var isMbr = new GlideRecord('sys_user_grmember');
isMbr.addQuery('group='+grp+^user='+userId);
isMbr.query();
if(isMbr.next())
return true;
else
return false;
//--you can place this logic inside a script include(lets say 'IncidentManager' for reusability
//-- call the function from any server side code e.g. business rule
new IncidentManager().isMemberOfCustom(current.caller_id, current.assignment_group)
//--you can place this line in the condition block of the business rule
Regards,
Anirban

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-03-2020 06:39 AM
Hi,
Updated line below.
gs.getUser().isMemberOf(<group name>);
Mark correct/helpful based on impact.
Thanks,
Dhananjay.