Assigned To field Dependent on Assignment Group List Types

Community Alums
Not applicable

Hey Everyone, 

 

I have two field called Assignment Group List (reference sys_user_group)

and Assignee List (reference sys_user) and both are list field types. My client wants to select multiple groups and the Assignee List needs to only show the members of the groups they selected from the Assignment Group List (these can be indefinite amount of groups). 

 

 

The problem is that my code is only working for one group selected and NOT for multiple groups selected.   

 

What am I doing wrong? 

This is my script include:

var mocFilterAssigneeList = Class.create();
mocFilterAssigneeList.prototype = Object.extendsObject(AbstractAjaxProcessor, {
filterAssignedTo: function(group) {
      var users = [];
		var getGroupMembers = new GlideRecord('sys_user_grmember');
		getGroupMembers.addQuery('group', group);
		getGroupMembers.query();
		while (getGroupMembers.next()) {
			users.push(getGroupMembers.getValue('user'));
		}
		return 'sys_idIN' + users.toString();
	   
	
	 },
    type: 'mocFilterAssigneeList'
});

 

My advanced reference qualifier: 

javascript: new mocFilterAssigneeList().filterAssignedTo(current.u_assignment_group_list);

 

This reference qualifier is on the Assignee List field. 

 

Can I actually do this?

2 REPLIES 2

Harsh Vardhan
Giga Patron

Hi @Community Alums  Try with below code.

 

var mocFilterAssigneeList = Class.create();
mocFilterAssigneeList.prototype = Object.extendsObject(AbstractAjaxProcessor, {
filterAssignedTo: function(group) {

var arr = group.toString().split(',');
      var users = [];
for(var i = 0; i < arr.length; i ++){
		var getGroupMembers = new GlideRecord('sys_user_grmember');
		getGroupMembers.addQuery('group', arr[i]);
		getGroupMembers.query();
		while (getGroupMembers.next()) {
			users.push(getGroupMembers.getValue('user'));
		}
}
		return 'sys_idIN' + users.toString();
	   
	
	 },
    type: 'mocFilterAssigneeList'
});

 

you need to use for loop here to iterate multiple values from group field. 

 

Please try.

 

Thanks,

Harsh

 

 

AshishKM
Kilo Patron
Kilo Patron

Hi @Community Alums , 

Please re-check the below code line

filterAssignedTo(current.u_assignment_group_list) , here this variable hold the sys_id of groups with delimiter ( , ) separated and when there is only one group .... it works perfectly ... in the below addQuery();

 

getGroupMembers.addQuery('group', group);

 

replace the above line with below one, using IN logical operator for all groups selected.

 

getGroupMembers.addQuery('group','IN', group);

 

-Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution