User field should show users depending on the selection group selected in group field

anushadande1793
Tera Contributor

Hi 

 

I had requirement to allow the user to select multiple users (list collector type) on user field and users should be populated depending on the group selected on group field referring to sys_user_group table. Can you please help me how to achieve this. I have given a trail calling script include from user field and writing onchange client script but not working . I have given below reference qualifier as well by referring user field to group member table but created field is showing up as it has display value as true . I tried removing this dispaly value and adding other fields to show up using variable attributes but no luck, display value is showing up 

javascript&colon;"group="+current.variables.<group_variable_name>;

 

Can someone help on the script part how to achieve this

 

Thank you,

Anusha

7 REPLIES 7

Brian Lancaster
Tera Sage

You will need to create a script include. Then call that from the variables reference qualifier. The variable should point to the sys_user table as the script include will return the users who are a member of the group. I made mine client callable in case I ever needed to use a client script to call it. Below is the script include code.

var UserGroupSCI = Class.create();
UserGroupSCI.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	getMembers: function(groupId){
		var id = [];
		var gr = new GlideRecord('sys_user_grmember');
		gr.addQuery("group", groupId);
		gr.query();
		while(gr.next()){
			id.push(gr.getValue("user"));
		}
		return "sys_idIN"+id.join();
	},

    type: 'UserGroupSCI'
});

The reference qualifier should look like this.

javascript&colon; new UserGroupSCI().getMembers(current.variables.<group_variable_name>);

Hi Brian,

It is not working as expected. Instead group members it is showing all users from user table.

I have given as user field as list collector and written given script include and called this script include from reference qualifier like below 

javascript&colon;new PopulateUser().getUsers(u_group_name);

But no luck. I have simply tried using refernce qualifier by keeping user field to group member table but it is giving created date as display value of created date  is true. But I don't want to change this as it is global change. Can you please help me with the solution

 

Thanks

Anusha

Chandra18
Mega Sage

Hi @anushadande1793,

I am Using Reference Qualifier it is working for me in Service portal (For native view you need to click on Run-Filter button after choose the Group). I am Choosing "CAB Approval" as a group and it is showing the group member in list collector variable.

Chandra18_0-1734269855514.png

Chandra18_1-1734269957712.png

 

May You choose sys_user table You need to take "sys_user_grmember" as list table on list collector variable.(Please see below screen shot).

Chandra18_2-1734270114828.png

 

Note: If you are seeing the created date instead from user name you need to change display=true for user field in sys_user_grmember table as below:

Chandra18_3-1734270291879.png


Please accept as solution!

Thank You!
Chandra

 



Hi @anushadande1793 ,

Did this way resolved your issue ? Let me know if you need any further assistance!

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful".

Thank You!