Adding User in a group via related list

sattar3
Tera Contributor

Hello All,

 

We have a table called "u_site_function" which is having a related list called "Leads".

 

When we select any user in the Leads related list then the user should be automatically added to a specific group called "SITE LEADS".

 

Can someone please help how to achieve this?

 

Thanks,

Sattar

3 REPLIES 3

Mark Manders
Mega Patron

Check on the 'leads' record. Are you creating a real record on a custom table, or is it a relationship table? 

On change of that table (either one of the two), trigger a flow and create a sys_user_grmember record whit the group as group and the user as the user triggered on the created record.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

SriharshaYe
Kilo Sage

Hi @sattar3 , 

To add users to a group via the related list , follow below steps:

  1. navigate to system defination > relation ships . create a relationship & add it to the table (configure->related list ) . 
  2. create a ui action (list choice), to add selected users to the specific group (i.e whenever you select specific users from the related list then perform action on that selected rows -> by clicking on that  ui action . add the below code in ui action : 
var gr = new GlideRecord('sys_user_grmember');
gr.initialize();
gr.user = current.sys_id;
gr.group = '3457309847bf421096e4224f316d43b8';
gr.insert();
gs.addInfoMessage('User has been successfully added to the group.');

whenever user selects the specific users from the related list and  clicks on that ui action then they will be added to that specific group.Screenshot 2025-01-21 at 6.09.47 PM.png

 

if my solution is helpful , please mark it as helpful .

 

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@sattar3 

you didn't share some more details, screenshots etc

How is that Leads table related to Site function table?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader