Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Reference qualifier for group variable to display only groups for the selected user

Ogrecic
Kilo Contributor

Hi All!

I'm currently building a catalog item for a request to remove user from groups. There is firstly a user field from sys_user table and then groups field. What I'm trying to do is to link these 2 fields so when the user is selected, in the groups field would appear only the groups that this particular user is part of. Yet no success. Any ideas? 

Thank you in advance. 

Best regards,

Oleg.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

You will have to create reference qualifier for the 2nd variable and call script include function

how to call script include in 2nd variable

javascript: 'sys_idIN' + new GetGroupMembers().getGroups(current.variables.userVariableName);

Script Include:

var GetGroupMembers = Class.create();
GetGroupMembers.prototype = {
	initialize: function() {
	},

	getGroups:function(user) { 
		
		var group_array = [];
		var getMembers = new GlideRecord('sys_user_grmember');
		getMembers.addQuery('user ',user);
		getMembers.query();
		while(getMembers.next())
		{
			var groupSysId = getMembers.getValue('group');
			group_array.push(groupSysId);
		}
		return group_array;
	},

	type: 'GetGroupMembers'
};

Regards
Ankur

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

View solution in original post

6 REPLIES 6

what is not working?

did you add gs.info() to debug

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

RudhraKAM
Tera Guru

This might be Old post but just adding other option, so that some one can use it , 

 

In the Reference variable , Select group member table and use the group sysID , this will fix the issue 

RudhraKAM_0-1689942149935.png