Get only members from a group (variable)

rafaelalves4337
Tera Contributor

Hello all,

 

I have a reference variable(select_the_group_to_add_remove_users) that is collecting all the groups that the requested_for is the manager. (working fine)

Screenshot_171.jpg

 

I have another variable list collect (please_select_the_user_to_be_added_to_the_group) collecting from sys_user.

Screenshot_172.jpg

 

This variable should only show members from the first variable (select_the_group_to_add_remove_users), group that the manager selected first.

 

I already tried some scripts, script included and nothing is working for me.

 

Can I have some help here?

 

Thank you in advance.

1 ACCEPTED SOLUTION

swathisarang98
Giga Sage

Hi @rafaelalves4337 ,

 

You can create a advance  reference qualifier and call a script include in that you can return the group members as shown below, I have tried the below in my pdi its working,

 

Reference qualifier,

swathisarang98_0-1715972849903.png

 

 

javascript: new getManagerGroup().getUser(current.variables.select_the_group_to_add_remove_users);

 

 

 

Script inlcude:

swathisarang98_1-1715972922287.png

 

 

var getManagerGroup = Class.create();
getManagerGroup.prototype = {
    initialize: function() {
    },

	getUser: function(groupID){
		
		var gr = new GlideRecord('sys_user_grmember');
		gr.addQuery('group',groupID);
		var arr =[];
		gr.query();
		while(gr.next()){
			arr.push(gr.getValue('user'));
		}
		return 'sys_idIN' + arr;

	},

    type: 'getManagerGroup'
};

 

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

View solution in original post

8 REPLIES 8

Gangadhar Ravi
Giga Sage

add this in advanced reference qualifier of second variable . update that first_variable in script with your variable name 

 

javascript:'sys_idIN'+getIDs(current.variables.first_variable); function getIDs(grp){var m=GlideUserGroup.getMembers(grp);var ids=''; while (m.next()){ids+= (m.user+',');} return ids;}

 

 Please mark my answer correct and helpful if this works for you.

It did not work, it's bringing all the users in the sys_user table.

chaudharymahesh
Mega Sage

Try below:

 

Script Include:

 

 

var groupUtils = Class.create();
groupUtils.prototype = {
    initialize: function() {
    },
	getGroupMembers: function(group) {
		var groupMember = new GlideRecord("sys_user_grmember");
		groupMember.addQuery("group", group);
		
		groupMember.query();
		var ids = "";
		while (groupMember.next()) {
			if (ids != "")
				ids += ",";
			ids += groupMember.user.toString();			
		}
		
		return "sys_idIN" + ids;	
	},
    type: 'groupUtils'
};

 

 
memahesh_1-1715967693613.png

 

Next, update the reference qualifier on second variables like below:

 

 

javascript: new groupUtils().getGroupMembers(current.variables.select_the_group_to_add_remove_users);

 

 

 

memahesh_2-1715967760143.png

 

 

 Please mark my answer correct and helpful if this works for you.

 

Mahesh Chaudhary
Senior Technical Consultant

It did not work too, it's bringing all the users in the sys_user table.