Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Advanced reference qualifer

josh_brostoff
Giga Contributor

I am looking to make an advanced reference qualifier for a user reference field.   I want it so when a this field is selected, only certain members from a group show up.   What would the script method be?

1 ACCEPTED SOLUTION

Hi Josh,



You need to write your own custom script include. I have just created one. Below is the code.




--


var GroupUtil = Class.create();


GroupUtil.prototype = {


      initialize: function() {


      },


  memberofGroup:   function(){


  var users=[];


  var grp = new GlideRecord('sys_user_grmember');


  grp.addQuery('group','1c590685c0a8018b2a473a7159ff5d9a');


  grp.query();


  while(grp.next()) {


  users.push(grp.getValue('user'));


  }


  gs.addInfoMessage('sysIDIN'+users.join(','));


  return 'sys_idIN'+users.join(',');


  },


      type: 'GroupUtil'


};


---


Here is the screen



Screen Shot 2016-02-04 at 7.54.05 PM.png




You need to call this from ref qualifier.



javascript:new GroupUtil().memberofGroup()




hope this helps



Cheers


Srini


View solution in original post

6 REPLIES 6

josh_brostoff
Giga Contributor

I tried the following but it didn't work:



javascript:gs.getUser().isMemberOf('insert group name here');


This would be a little more complex than that. The reference qualifier is basically a query you're running against the user table, so it has to be formatted in that way. What you'd need to do is write a simple script include that queried the sys_user_grmember table and returned a comma separated list of user sys_ids. You would return something like 'sys_idIN' + listOfSysIDs


Hi Josh,



You need to write your own custom script include. I have just created one. Below is the code.




--


var GroupUtil = Class.create();


GroupUtil.prototype = {


      initialize: function() {


      },


  memberofGroup:   function(){


  var users=[];


  var grp = new GlideRecord('sys_user_grmember');


  grp.addQuery('group','1c590685c0a8018b2a473a7159ff5d9a');


  grp.query();


  while(grp.next()) {


  users.push(grp.getValue('user'));


  }


  gs.addInfoMessage('sysIDIN'+users.join(','));


  return 'sys_idIN'+users.join(',');


  },


      type: 'GroupUtil'


};


---


Here is the screen



Screen Shot 2016-02-04 at 7.54.05 PM.png




You need to call this from ref qualifier.



javascript:new GroupUtil().memberofGroup()




hope this helps



Cheers


Srini


This looks perfect, Srini! My only question is: could this already exist somewhere by default? I didn't find anything when looking through the baseline Script Includes, but it seems like it would be a common use case that might already be addressed.