Populate the list of group members in a list collector as per the group selected in a reference field above

AkashD
Kilo Expert

Hey folks,

I have a requirement for a catalog item where I need to populate the list of group members in the right bucket of the list collector as per the group selected in a reference field above.

The form looks like this as of now :

find_real_file.png

The first field is reference to "sys_user_group" while the list collector is showing the users with a simple reference qualifer which says "active=true^user_name!=empty".

What I'm basically trying to achieve is to edit the group members (add or remove) using this form; I know that could later be achieved via the workflow, but as of now I'm struggling with this. I've tried plenty of scripts available in the community, but none of them seem to be working for me. 

Any slight help would be really appreciated! Thanks in advance!

1 ACCEPTED SOLUTION

@Ankur Bawiskar,

The code which I'm trying is below :

Client Script :

group_members is the name of the list collector

find_real_file.png

 

Script Include :

find_real_file.png

 

Any slight help would be highly appreciated, thanks!

View solution in original post

15 REPLIES 15

Hi @Ankur Bawiskar ,

I tried following this post, but cannot get it to work. Looking at my script include and client script. Do you spot anything I did wrong?

 

var reqUtilsAjax = Class.create();
reqUtilsAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getGroupMembers: function() {
		var grpID = this.getParameter('sysparm_gid');
		var memObj = new GlideRecord('sys_user_grmember');
		memObj.addQuery('group', grpID);
		memObj.query();
		var nArray = [];
		var vArray = [];
		while (memObj.next()) {
				nArray.push(memObj.user.getDisplayValue().toString());
				vArray.push(memObj.user.toString());
		}
		var retValue = nArray.toString() +  '|' + vArray.toString();
		return retValue;
	},	
    type: 'reqUtilsAjax'
});

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
	
	g_form.setValue('members', '');
	
	var ga = new GlideAjax('reqUtilsAjax');
	ga.addParam('sysparm_name', 'getGroupMembers');
	ga.addParam('sysparm_gid', 'newValue');
	ga.getXML(buildList);
	}

function buildList(response) {
	var answer = response.responseXML.documentElement.getAttribute("asnwer");
	var memArray = answer.split('|');
	var memNames = memArray[0];
	var memValues = memArray[1];

	g_form.setValue('members',memValues);

   //Type appropriate comment here, and begin script below
   
}

 

One Reference field for my sys_user_groups and the List Collector for my sys_user.