How can I filter a reference field (referencing sys_user) to only show members of a specific group?

Nick Derbawka
ServiceNow Employee
ServiceNow Employee

Hello!

 

I am building a Catalog Item where I need the requestor to select the user who will be working on their request (defining the assigned_to out of the Record Producer itself) out of the assignment group that triages all of these requests; the issue I am running into is that I am not able to create a specific filter/reference qualifier that would accomplish this (i.e. only show users within the specific assignment group).

 

The sys_id of the group itself is: '290177c8fb4cae50bb47e5374eefdc3e' --> if someone could help me figure this out (I believe I need a Script Include and then a reference qualifier on the variable itself?) I will quickly award a "solved" reply.

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@Nick Derbawka 

I believe that variable is referring to sys_user.

so use this in advanced reference qualifier so that it shows members of only that group

javascript:
var user = [];
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group", "290177c8fb4cae50bb47e5374eefdc3e");
gr.query();
while (gr.next()) {
    user.push(gr.getValue('user'));
}
var query = 'sys_idIN' + user.toString();
query;

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

OmkarC
Tera Guru

Hi @Nick Derbawka

In the advanced reference qualifier you can write the script or You can also use the Script include. As advanced reference qualifier approach script is already posted. 

For the script include approach here is the script:

 

//In advanced reference qualifier add this
javascript: new application_scope.script_IncludeName().functionName('sys_id_of_group');

//Here is Script Include function
functionName : function(grpId){
		var grpUsers = [];
		var grpM = new GlideRecord("sys_user_grmember");
		grpM.addQuery("group",grpId);
		grpM.query();
		while(grpM.next())
		{
			grpUsers.push(grpM.user.toString());
		}

		var userList = 'sys_idIN' + grpUsers.toString();
		return userList;
	},

 

 

Thanks & Regards,
Omkar

View solution in original post

4 REPLIES 4

rohansargar
Kilo Guru

Hello @Nick Derbawka,

 

Try this code,

 

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

getUsers: function() {
var users = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', '290177c8fb4cae50bb47e5374eefdc3e'); // Assignment group sys_id
gr.query();
while (gr.next()) {
users.push(gr.user.toString());
}
return users;
},

type: 'GetUsersByAssignmentGroup'
};

 

Mark as helpful if you got answer for your question.

Best Regards,

Rohan

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Nick Derbawka 

I believe that variable is referring to sys_user.

so use this in advanced reference qualifier so that it shows members of only that group

javascript:
var user = [];
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group", "290177c8fb4cae50bb47e5374eefdc3e");
gr.query();
while (gr.next()) {
    user.push(gr.getValue('user'));
}
var query = 'sys_idIN' + user.toString();
query;

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Nick Derbawka 

Thank you for marking my response as helpful.

I also shared a working solution.

As per new community feature you can mark multiple responses as correct.

If my response helped please mark it correct as well so that it benefits future readers.

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

OmkarC
Tera Guru

Hi @Nick Derbawka

In the advanced reference qualifier you can write the script or You can also use the Script include. As advanced reference qualifier approach script is already posted. 

For the script include approach here is the script:

 

//In advanced reference qualifier add this
javascript: new application_scope.script_IncludeName().functionName('sys_id_of_group');

//Here is Script Include function
functionName : function(grpId){
		var grpUsers = [];
		var grpM = new GlideRecord("sys_user_grmember");
		grpM.addQuery("group",grpId);
		grpM.query();
		while(grpM.next())
		{
			grpUsers.push(grpM.user.toString());
		}

		var userList = 'sys_idIN' + grpUsers.toString();
		return userList;
	},

 

 

Thanks & Regards,
Omkar