To check user is part of the group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 05:46 PM
Hi,
In the catelog activity in the work flow we are adding the requester to the group using the script.I need to add condition to check if user was
added properly to the group.In short I need to verify the requestor is part of that group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 07:10 PM
Replace groupName
gs.getUser().isMemberOf(groupName));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 09:09 PM
HI Gomathshankar,
You can validate this with the help of script mentioned below.
var count = 0;
var gr = new GlideRecord("sys_user_grmember") // table that stores the group member details
gr.addQuery("user",requestor);// pass the requestor field column name like current.request.requested_for for RITM table.
gr.addQuery("group",group); // pass in the group sys_id
var count = gr.getRowCount();
if (count > 0){
gs.log("User added");
else {
gs.log("User not added");
}
Hope this helps you.
Regards,
Sneha Binani

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 10:32 PM
Hello Gomathyshankar,
You can create "If" activity in the workflow and return true or false output. Script will be
// This script needs to set answer to 'yes' or 'no' to indicate the state of the activity.
//
// For example,
answer = ifScript();
function ifScript() {
if (gs.getUser().isMemberOf(current.variables.PASSGROUPNAME HERE))) { //Replace PASSGROUPNAME HERE with exact name of the catalog variable in case group name is store in variable for variable it will PASSVARIABLENAME.getDisplayValue()
return 'yes';
}
return 'no';
}
Reference:
http://wiki.servicenow.com/index.php?title=Getting_a_User_Object#gsc.tab=0
Condition Activities - ServiceNow Wiki
Let me know if you have any questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2017 07:41 AM
If you need to check if the user is a member of at least one of a GlideList of groups, use something like this:
answer = checkGroupsOnComp();
function checkGroupsOnComp(){
var access_groups = (current.u_component.u_groups.toString()).split(",");
var users_groups = gs.getUser().getMyGroups().toArray();
converted_list = [];
for (var i=0; i < users_groups.length; i++){
converted_list.push(users_groups[i] +'');
}
var au = new ArrayUtil();
var combined = au.concat(access_groups, converted_list);
var uniq = au.loose_unique(combined); //loose_unique is a copy of unique but the comparison operator is == not ===
return (combined.length != uniq.length); //if there's a dupe, they are a member of at least one group
}
loose_unique is sometimes needed since the strings could have different classes.