Custom Reference field return group members from one group

anfield
Tera Guru

I have a custom reference field where i want to return all the group members from one group (to be able to select one). At the moment it points to sys_user_grmember and it just returns the group name multiple times. I'd rather not customize anything about sys_user_grmember as that is used in other modules. Found the encoded query below to add into the attributes of the reference field, but it doesnt seem to have an affect.

 

Also tried to modify the columns attribute using ref_ac_columns=user, but that do anything either.

 

Encoded query tried:

javascript&colon;var gr = new GlideRecord('sys_user_grmember');gr.addQuery('group',"<group sys id here>");gr.query();var users='';while(gr.next()){users+=gr.user.sys_id + ",";}"sys_idIN" + users;

 

 

1 ACCEPTED SOLUTION

I used a clean PDI to add a field called App Devs on the incident table to only return the users in the Application Development group.

Final outcome after clicking lookup:

drewmasonNR_0-1710990164161.png

Column entry:

drewmasonNR_1-1710990321021.png

Script Includes:

drewmasonNR_2-1710990374548.png

Group:

drewmasonNR_3-1710990490046.png

 

 

View solution in original post

12 REPLIES 12

I used a clean PDI to add a field called App Devs on the incident table to only return the users in the Application Development group.

Final outcome after clicking lookup:

drewmasonNR_0-1710990164161.png

Column entry:

drewmasonNR_1-1710990321021.png

Script Includes:

drewmasonNR_2-1710990374548.png

Group:

drewmasonNR_3-1710990490046.png

 

 

anfield
Tera Guru

This works. Very helpful Thanks

Community Alums
Not applicable

I have gone through all the replies, I found better resolution among all listed.
Please go through below knowledge article

KB0831564: 

How to select only users of a specific group into a reference field

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0831564

Note: Some times it will throw error "GlideUserGroup is not allowed in scoped applications"
in that case you can use below advance ref qualifier: (replace sysid with your Group's sysid.

javascript&colon;'active=true^sys_idIN' + getIDs('f21254021bc1b110870286e1604fcf0e'); function getIDs(groupSysID) { var members = []; var gr = new GlideRecord('sys_user_grmember'); gr.addQuery('group', groupSysID); gr.query(); while (gr.next()) { members.push(gr.user.toString()); } return members.join(','); }