How to automatically add new users to a group when they are added to users

Gemma4
Mega Sage

 

Hi everyone!

I would like to ask your assistance, I have this requirement when a new user is added to the sys_users table I need them automatically added to the PM submitter group. I created a business rule but it is not automatically adding new users. Any suggestions on what the best practice to achieve this would be. 

 

 

thanks

1 ACCEPTED SOLUTION

Hello @Gemma4 ,

What I observed in the First screenshot, You added Group as PM Submitter, but you forgot to add the User field with the value from Trigger->User Record

Please check the Second Screenshot from my Answer

 

I hope this clears your question

 

Please mark my answer helpful and correct, If it helps you

Thank you

 

 

Please mark my answer helpful  & correct if it helps you
Thank you

G Ramana Murthy
ServiceNow Developer

View solution in original post

11 REPLIES 11

Ahmed Drar
Tera Guru
Tera Guru

@Gemma4  - You can easily create a flow that runs when a new user is create and then create an action that inserts this new user into PM submitter group

 

 

I hope this helps.

Ahmed

Please mark my answer as Correct / Helpful based on the Impact

Community Rising Star 2023

Hi @Ahmed Drar 

I tried a flow but unfortunately when I create a user it is not adding the user to the group. Attached is the trigger and flow used. Any suggestions as I'm new to using flow designer.

 

SanjivMeher
Kilo Patron
Kilo Patron

In the flow designer, you need to use Create Record action to create a record in the sys_user_grmemeber table.

And also pass both group as well as the user you want to add to the group, which should add the user membership.


Please mark this response as correct or helpful if it assisted you with your question.

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Gemma4 ,

 

You can create a business rule on "User" table with below configs:

 

When to run: after

Operation : Insert

(Apply appropriate conditions only when it suppose to consider specific users(type of users) else no need to add condition)

 

Advanced Script: 

 

(function executeRule(current, previous /*null when async*/) {

	// Add your code here

	var gr = new GlideRecord('sys_user_grmember');
	gr.initialize();
	gr,group = '<sys ID of PM submitter Group>';
	gr.user = current.sys_id;
	gr.insert();

})(current, previous);

 

 

Please mark my answer helpful & accepted if it resolves your query.

 

Thanks,

Danish