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
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

swathisarang98
Giga Sage
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

Still not working....

 

I don't know what I'm doing wrong...

 

This is the result, all the users showing in the list, and in this particular group there are only 2 people.

Screenshot_175.jpg

 

Script Include is like this

 

Screenshot_174.jpg

 

This is the variable to select the users:

Screenshot_173.jpg

@rafaelalves4337  reference qualifier written is wrong please correct it according to below image,

 

swathisarang98_0-1715974970831.png

 

 

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

Regards,

Swathi Sarang

 

Thank you @swathisarang98 .

 

It worked!!