checking group membership via Client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2014 08:56 AM
Hi,
I have a Catalog Item where users can select a group and a list of users. What I want is to look at that group members and set up an alert (or confirm) that says whether any of the users selected are already in that group
Or I guess I could do this maybe via altering the list collector filter?
My attempt at a client script that makes a GlideAjax call is:
function onSubmit() {
var group = variables.group; // group from reference variable on sys_user_group table
var users = variables.requested_for; //comma seperated list of users from list collector.
var ga = new GlideAjax('GroupMember');
ga.addParam('sysparm_name','groupMember');
ga.addParam('sysparm_group',group);
ga.getXML(GroupMemberParse);
function GroupMemberParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
}
... and the script include is:
var GroupMember = Class.create();
GroupMember.prototype = Object.extendsObject(AbstractAjaxProcessor, {
groupMember: function() {
var group = this.getParameter('sysparm_group');
//return "Hello " + this.getParameter('sysparm_user_name') + "!";
return _getusers(group);
},
_getusers: function(user) { // this function is not client callable
var strUsers = '';
var grRole = new GlideRecord('sys_user_grmember');
grRole.addQuery('user', user);
grRole.query();
while (grRole.next()) {
if (strUsers.length > 0) {
// build a comma separated string of groups if there is more than one
strGroups += ',' + grRole.user;
} else {
strGroups = '' + grRole.user;
}
}
return strUsers;
}
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2014 09:02 AM
You're passing a group from your client script to the script include and then within your script include into your private _getusers function. It looks like that function is then using the group you passed as a user in the query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2014 07:12 AM
Hi,
I took out the private bit as it seemed to not be working... is this a bad idea as I don't think the class GroupMember.
This above code gives me group members (now I just hae to work out another bit (it's all a learning exercise as well you see )
My client script has the output as well which is nice...
I tried adding in a retrun false statement if the result of the confirm was false but it didn't work as I'd expected.... I basically DONT want it to submit if the user clicks Cancel on eth confirm message...?
Any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2014 07:39 AM
Hi Ben,
Try this
var x =confirm("your message");
if(x='false')
{
return false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2014 08:09 AM