Advanced Reference Qualifier members of a specific group

leslie8
Mega Expert

I have a Reference field in a Record Producer. The Reference field points to the User table.

I want the field to only display members of a specific group.

How can I build the reference qualifier to restrict the choices to the users who are members of the group?

Can I use an encoded query string or will this require a script as described in the wiki article?

Reference Qualifiers - ServiceNow Wiki

Thank you

1 ACCEPTED SOLUTION

Mike Allen
Mega Sage

You will have to have something query the sys_user_grmember for the users in that group, then feed it into your reference qualifier in a sys_idIN type statement, like:



Re: Reference Variable Filtered by Group


View solution in original post

4 REPLIES 4

Mike Allen
Mega Sage

You will have to have something query the sys_user_grmember for the users in that group, then feed it into your reference qualifier in a sys_idIN type statement, like:



Re: Reference Variable Filtered by Group


Ahmed Drar
Tera Guru
Tera Guru

First you need to create a client callable script include query from sys_user_grmember, would be something like that


var filterUser = Class.create();


filterUser.prototype = Object.extendsObject(AbstractAjaxProcessor, {


  filter: function(groupID){



  var Buildusers = ' ';


  var usr = new GlideRecord('sys_user_grmember');


  usr.addQuery('group',groupID);


  usr.query();


  while(usr.next()) {


  if (Buildusers.length > 0) {


  //build a comma separated string of users if there is more than one


  Buildusers += (',' + usr.user);



  }


  var result = 'sys_idIN' + Buildusers;


return result;



  },


      type: 'filterUser'


});



after writing your Script include you need to call your script from the reference qual


mitzaka
Mega Guru

You could also use encoded script, something like:



javascript:var gr = new GlideRecord('sys_user_grmember');gr.addQuery('group',"<insert your group's sys_id>");gr.query();var users='';while(gr.next()){users+=gr.user.sys_id + ",";}"sys_idIN" + users;


Community Alums
Not applicable

nice touch. You can do this without cerating a custom script include.