- 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-03-2020 08:05 AM
isMemberOf function works only for current user. If you want to check for incident's caller id, You have to use GlideRecord query in business rule. Query will be something like below :
Please mark my answer correct/helpful, If it helped you.
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user',current.caller_id);
gr.addQuery('group',<servicenow_group>);
gr.query();
if (gr.next())
{
<Perform required step>
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-03-2020 08:22 AM
Hi,
please test this in condition and it should work
gs.getUser().getUserByID(current.caller_id).isMemberOf('<group name>');
Mark ā
Correct if this solves your issue and also mark š Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-04-2020 01:02 AM
Hi Ankur
This is not working. I suppose I should mention the issue is in scoped application scenario.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-04-2020 10:41 PM
Hi,
The reason is below
getUserByID() is not allowed in scoped app hence it won't work
gs.getUser().getUserByID(current.caller_id).isMemberOf('<group name>');
the above condition would work fine in global scope but not in custom scope
As already suggested you need to call script include function from condition field and in the function check the group membership by doing query
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-05-2020 09:56 PM
Thanks Ankur.