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

Can you share what you've got now exactly? When I reproduce with a quickly newly scoped app, it works instantly.

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

find_real_file.png

find_real_file.png

 

Looks the same 😞

So the gs.info is also not written to the logs, only an error instead? Could you add more gs.info statements, for example at the beginning of the function, within the while, etc.. To see if the Script Include is exectuted and at what point it fails.

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

None of the gs messages are in the logs, is this because the reference field is to the sys_user table?

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

getMember: function() {
gs.info('function started');

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()) {
gs.info('in the while loop');

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

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

},

type: 'GetGroupMember'

});

sys_user indeed, I assume you've got this also (also seeing your image, it mentiones User).

So somehow the Script Include or the function is not triggered. Don't see it yet 😞

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn