How to add Script include in Reference Qualifier

Abdul333
Tera Contributor

Hello All,

 

I created a custom field called "Special Group".

Field type "List":

Reference to "sys_user" table

In that field we need to show only a particular group members.

Abdul333_1-1701691970496.png

 

I written Script include like this:

 

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

getUsersFromAppEngineAdminsGroup: function() {
var userList = [];

var groupGr = new GlideRecord('sys_user_grmember');
groupGr.addEncodedQuery('group=477a05d153013010b846ddeeff7b1225');// sys_id of App Engine Admins group
groupGr.query();

while (groupGr.next()) {
var user = new GlideRecord('sys_user');
if (user.get(groupGr.user)) {
userList.push(user.name.toString()); // Assuming name is used as the reference field
}
}

return userList;
},

type: 'GetUsersOfGroup'
};

 

how should i call this in that field "Special group" reference qualifier so that only

Please correct me if i did anything wrong.

2. In the list it showing sys_id's, how should we show user "names instead of sys_ids"?

 

@Ankur Bawiskar @SANDEEP28 @Community Alums 

 

 

Thanks,

Abdul

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Abdul333 

update script include as this

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

	getUsersFromAppEngineAdminsGroup: function() {
		var userList = [];

		var groupGr = new GlideRecord('sys_user_grmember');
		groupGr.addEncodedQuery('group=477a05d153013010b846ddeeff7b1225');// sys_id of App Engine Admins group
		groupGr.query();
		while (groupGr.next()) {
			userList.push(groupGr.getValue('user'));
		}

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

	type: 'GetUsersOfGroup'
};

Call it like this from the advanced ref qualifier

javascript: new GetUsersOfGroup().getUsersFromAppEngineAdminsGroup();

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

8 REPLIES 8

@Ankur Bawiskar  now it works.

Abdul333_0-1701698932336.png

 

 

Thanks,

Abdul

@Abdul333 

Glad to know.

Please mark my response as correct and close the thread.

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

@Abdul333 

Could you mark my response as correct and close the thread?

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

@Ankur Bawiskar  Done.

 

Thanks

Abdul