get list of groups user belongs to

gtk
Mega Sage

we have created a new custom table with name u_work_group

in which it is having list of 50+ groups, and now we got a requirement that

create a field which refers to sys_user table

and when user is selected then ln a text box to be shown with list of groups that user is member of

agent - type is reference - points to sys_user

groups - type is text box - get group of user

(groups to be separated with comma [,])

16 REPLIES 16

can you suggest how to relate/sync groups to table,


Dave Smith1
ServiceNow Employee
ServiceNow Employee

When you say "create a field which refers to sys_user table" , it sounds like you want to use a use a reference field.



If you go to the user record, you can see what groups they belong to there.   I may be misunderstanding what you're doing here, but it sounds like effort duplication.


looks good,



but here our requirement is to create   a separate table is to get groups from AD and group members i.e., we should not add/remove groups/group members but it has to sync from AD to SNOW and maintain table to be like an sys_user_group [replicate] in table.


and to create a service request with fields User and Groups : if any user is ls selected then in groups field it   has to populate the groups [AD]user belongs to


1. Create a client script and pass the user sysid.


2. Create a Script Include and get the user sysid parameter and write the below code to fetch the groups:



var usersysid = this.getParameter("sysparm_usersysID");// fetch sysid here


var gr = new GlideRecord("sys_user_grmember");


gr.addQuery("user",usersysid);


gr.query();


while(gr.next())


{


gs.print("User is in group::"+gr.group.getDisplayValue());


}



3. collate the groups here and return.


4. In the client script set the values by   g_form.setValue.



NOTE : If using a BR simply use GlideRecord code and set it via :
gr.work_notes = Value;



Regards,


Sachin


it's not working