need to populate assignment group members in list collector field

lata1
Tera Contributor

Hi all,

I have group field(reference to group) when i select any group, that group members need to populate in list collector field(List collector reference to user ).

i want to show that particular group members in list collector field remaining group users i want to restrict...

Thanks in advance...

 

27 REPLIES 27

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Lata,

Do you want this to run when record is inserted/updated? if yes then you can use before insert/update BR

sample script below

var currentGroup = current.assignment_group;

var arr = [];

var members = new GlideRecord('sys_user_grmember');
members.addQuery('group', currentGroup);
members.query();
while(members.next()){

arr.push(members.getValue('user'));

}

current.<list_field> = arr.join(',');

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Kieran Anson
Kilo Patron

Hi Lata,

Is this on a cataolg item? If so, we have had this need and did the following. In the list collector reference qual, reference a script include that returns the required information. As an example

find_real_file.png

Below is the script include that is used

var GetGroupMembers = function() {
	var answer = ' ';
	var group = current.variables.group_name; //name of variable on catalog item to use as group reference.
	var group_members = new GlideRecord('sys_user_grmember');
	group_members.addQuery('group',group);
	group_members.query();
	
	while (group_members.next()) {
		if (answer.length > 0) {
			answer += (',' + group_members.user.sys_id);
		} else {
			answer = group_members.user.sys_id;
		}
	}
	return 'sys_idIN' + answer;
};

Hi, Checking in on whether my reply resolved your issue? If so please Mark Correct and /or 👍 Helpful if you find my response worthy based on the impact.
By doing so you help other community members find resolved questions which may relate to an issue they're having.

This worked perfectly for a client-side deployment, thank you.