Exclude a group of users from reference field which is using sys_user as reference

RudhraKAM
Tera Guru

Hello 

I have a requirement where in reference field  which is of reference sys_user table we need to exclude  IT group people from the list 

 

How to to solve this 

I found this article but not sure how to use this 

https://community.servicenow.com/community?id=community_question&sys_id=2ed1d7addbdcdbc01dcaf3231f96...

3 REPLIES 3

Dubz
Mega Sage

The reference qualifier just needs to get your subset of users and return a query string that will exclude them from the query when the field is opened. Create a script include and name it excludeITUsers. When you tab out it should populate the script field with some code which is defining the class. Add the following code in the bit it tells you to:

//name your function
excludeITUsers: function(){

//create an array
var arr = [];

//glide into the user group table
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', 'sys_id of the IT group');
gr.query();

//add it users sys_id to the array
while(gr.next()){
arr.push(gr.getValue('user');
}
//return the query string to say sys id is not one of the it guys
return 'sys_idNOT IN' + arr;
}

 

Call it as per that link: 

javascript: new excludeITUsers().excludeITUsers()

RudhraKAM
Tera Guru

Hello David ,, i used the same code but its not working , the only change i made was 

 

ok so you've configured it as a classless script include so you will need to call it in the advanced reference qualifier as below:

javascript: excludeIT()