- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2017 11:14 AM
Hi,
I need help with the UI action condition to check the users that are part of the groups listed in the field( type is list).
This is the condition I wrote, but it doesn't work.
current.u_implementation_group.toString.indexOf(''+gs.getUserId())!=-1|| gs.hasRole('cmc') && new ChangeRequestStateHandler(current).isNext("implement")
This is the field that I was mentioning earlier; this field is dynamic, and it get's the values from business service.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2017 02:16 PM
Looks like I forgot to add current in the condition. What it should be is:
new groupUtils().isMemberAny(current.u_implementation_group, gs.getUser())
Since I did not test the script, you could try running the function call in scripts background. Just be sure to get the sys_id of a record you want to test, as well as the user you are impersonating. I am guessing that this is part of a Change Request [change_request], so I have created this sample you can use to test:
var current = new GlideRecord('change_request');
current.get('TheSys_IdOfTheRecordHERE');
var usrObject = gs.getUser(); //Me
usrObject.getUserByID( Â'abel.tuter'); //Another user to test with;
var chk = new groupUtils().isMemberAny(current.u_implementation_group, usrObject);
gs.print(chk);
Hopefully there are not any errors in the script itself, otherwise you could separate out the actual function and test it in Scripts - Background:
var current = new GlideRecord('change_request');
current.get('TheSys_IdOfTheRecordHERE');
var usrObject = gs.getUser(); //Me
usrObject.getUserByID( Â'abel.tuter'); //Another user to test with;
var chk = isMemberAny(current.u_implementation_group, usrObject);
gs.print(chk);
function isMemberAny(grpString, myUsrObject) {
// isMemberAny: function(grpString, myUsrObject) {
var retValue = false;
if (grpString == '') {
return retValue;
} else {
grpArray = grpString.split(',');
for (var i=0; i < grpArray.length; i++) {
var chkMember = myUsrObject.isMemberOf(grpArray[i]);
if (chkMember) {
retValue = true;
}
}
return retValue;
}
// },
}
This should at least let you know if the function is working as expected. Hopefully the other portions of the UI Action condition are not being true and causing it to show.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2017 11:25 AM
Hi Eliana,
If I understand correctly you need to check whether logged in user is part of one of the groups listed in list type field mentioned. If so current.u_implementation_group.toString will return sys ids of groups not the list of users.
Regards,
Mayur

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2017 11:28 AM
It sounds like you may want to use gs.isMemberOf() in some fashion. Since your field is a list, and could contain more than one value, you'll need to loop through the groups in the field. For that reason, it may be wise to move the code to something like a Script Include for readability and so it can be reused.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2017 12:59 PM
Based upon the comments above, I put together a script include function that you can use. Here are the Script Include details:
Name: groupUtils
Accessible from: All application scopes
Description: Custom Include
Script:
var groupUtils = Class.create();
groupUtils.prototype = {
initialize: function() {
},
/**
* Checks if a user is a member of multiple groups defined within an array
*
* @param {string} grpString Comma delimited string of sys_id
* values of groups to search against.
* @param {object} myUsrObject The User Object to search against
* @return {Boolean} Returns true if the User is a member of one of the
* groups, otherwise returns false.
*/
isMemberAny: function(grpString, myUsrObject) {
var retValue = false;
if (grpString == '') {
return retValue;
} else {
grpArray = grpString.split(',');
for (var i=0; i < grpArray.length; i++) {
var chkMember = myUsrObject.isMemberOf(grpArray[i]);
if (chkMember) {
retValue = true;
}
}
return retValue;
}
},
type: 'groupUtils'
};
2. To use this in your condition, you would include the following somewhere in your condition:
new groupUtils().isMemberAny(u_implementation_group, gs.getUser())
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2017 01:59 PM
Hi Chris,
Thanks for your reply; I have created the script include like the one you mentioned above, but still when I impersonated other users that are not a part of the groups are able to see Implement UI action.