The CreatorCon Call for Content is officially open! Get started here.

reference field to return only users from a specific group

JJG
Kilo Guru

Hello, 

I have a reference field to the 'sys_user' table with the name 'name_of_recruiter'. I want the reference field to only show users who are in the recruiting group. However, it is returning every user. Is my script incorrect?

Script include:

var GetGroupMember= Class.create(); 

GetGroupMember.prototype = { 

getMember : function() { 

var x = 'e4d875a8db9a5300e21cfd131d961992'; //This is the sys_id of the recruiter group 

var user_array = []; 

var getMembers = new GlideRecord('sys_user_grmember'); 

getMembers.addQuery('group',x); 

getMembers.query(); 

while(getMembers.next()) { 

user_array.push(getMembers.user + ''); 

}

 return user_array.toString(); 

}};

Reference qualified in the 'sys_user' reference field 'name_of_recruiter'

 javascript:new GetGroupMember().getMember();

1 ACCEPTED SOLUTION

Ahhh it's Scoped!

Try with:

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

	getMember : function() { 

		var x = 'e4d875a8db9a5300e21cfd131d961992'; //This is the sys_id of the recruiter group 
		var user_array = []; 

		var getMembers = new GlideRecord('sys_user_grmember'); 
		getMembers.addQuery('group',x); 
		getMembers.query(); 

		while(getMembers.next()) { 
			user_array.push(getMembers.user + ''); 
		}

		gs.info('sys_idIN' + user_array.toString());
		return 'sys_idIN' + user_array.toString(); 
	
	},

    type: 'GetGroupMember'
	
});

Note there's also a gs.info for debugging purposes. So you could check the logs which query is returned and if it's what you would expect.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

13 REPLIES 13

SOLVED: there was a single space in front of the reference qualifier, thank you for all your help mark, your code works!

Thanks @Mark Roethof this worked for me as well - thanks for your help!

Thank you for sharing your screenshots and for the question - I had a similar question and this thread worked for me as well. Appreciate

Mark Roethof
Tera Patron
Tera Patron

Just reproduced also with your code and the slight adjustment (+ obviously used a different sys_id). Works fine here.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn