Only need members part of particular group to be visible

Kruthik M Shiva
Tera Contributor

Hi All,
I have a requirement to create a field which is of type reference, and it is referring to sys_user table but i have a requirement that the users which are part of one of the particular groups should only be visible. How to do this please do share pointers and script if required to achieve this.
Thanks in advance.

7 REPLIES 7

Fabian Kunzke
Kilo Sage
Kilo Sage

Hello,

 

Reference fields can have an advanced qualifier where you can define a script. Here you can call a script include of your choosing.

 

You script include must return a list of sys_ids of the users you need. Query the table "sys_user_grmember" table for the group in question and have the script return a comma seperated list of all user sys_ids. Then call that script include and add

 

 

javascript:"sys_idIN" + new myScriptInclude().my_refqual()

 

 

to the reference qualifier of the user reference field.

 

Hope this helps.

Regards

Fabian

Kalyani Jangam1
Mega Sage
Mega Sage

Hi @Kruthik M Shiva 

You can call this by using reference qualifier. Go to the field dictionary, select advanced reference qualifier and use below line

javascript: new AssignedGroup().SetAssigned();

AssignedGroup = It is Script include name

SetAssigned = It is function

***********************************************************************************************************

Below code will use in SI

SetAssigned: function(){
var num;
var gr=new GlideRecord("sys_user_grmember");
gr.addQuery('group','053cd11a5bda50106d8012300a81c721'); // sys_id of Group that only user will visible
gr.query();
while(gr.next()){

num += (',' + gr.user.toString());
 
}
return 'sys_idIN' + num;

},
***********************************************************************************************************
Please check and Mark Helpful and correct if it really helps you

Hi @Kalyani Jangam1 ,
I tried this script, but it is not working.

Hi @Kruthik M Shiva 

1)Please confirm your Script include is not client callable.

2) Please confirm your reference qualifier like this

Screenshot 2023-08-07 at 3.11.33 PM.png

 

you can use log message in script include for checking your code.

Please check and let me know if it helpful or not.