Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

reference qualifier script member of group

Karen Warren
Tera Contributor

This has come up for me enough times and I don't want to continue to rely on our outside implementers.

I need to create a reference qualifier that is scoped to a particular group. Can someone let me know what that script would look like? I thought I was close a couple times, but I keep missing it.   sys_user field that references only a particular group.

This would be a big help.

Thanks,

Karen

13 REPLIES 13

No problem.  



If you select "Advanced" for your type of Reference Qualifier on 'u_student_assigned_to', you can copy/paste the following to give you only users in a specific group.   Just insert your specific group's sys_id where I've noted.




1. Enter the following as the reference qualifier:



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;




2. You could also store the meat of that in a script include as a function, and then call it from your refqual...



Script Include: getGroupMembersList



function getGroupMembersList(groupId){


var gr = new GlideRecord('sys_user_grmember');


gr.addQuery('group', groupId);


gr.query();


var users='';


while(gr.next()){


        users+=gr.user.sys_id + ",";


}


return users;


}




Then in your refqual, you would call it as:



javascript:   "sys_idIN" + getGroupMembersList("<insert your group's sys_id>")






Either one of these methods should work for you.



Thanks,


-Brian


This is exactly the answer, cheers Brian


Thanks.  


I'm trying to do something similar, needing a list of all members of a certain group.


But when I Reference to the sys_user_grmember table, I can't seem to select a value from my list, nor does it autocomplete on typing....


What am I doing wrong? 😕


Hi Chris,



it would be best to lay out the details of your use-case/scenario, and provide the details/screenshots of what you are already trying.



e.g., Are you trying to pick a user?   Then your reference needs to be to [sys_user] instead, and you would use some script/qualifier to narrow the list based on what's in [sys_user_grmember].



if(more_detail == better_info){


      var result = what_you_are_looking_for;


}


return result:



 




Thanks,


-Brian