How to add role to the user by using flow designer

manoj kumar14
Tera Contributor
  1. Create a catalog item - with 2 variables

  2. one variable to get the requested for user, one to get the role

  3. once the request is submitted, should ask for approval from requested user's manager

  4. If approved assign the role to the user, if reject send a email to notify the rejection

 

for Ex:- newuser Role :- admin if we submit the record then it should add the role in roles table.

 

4 REPLIES 4

Sails
Kilo Sage

Hello,

You can use the 'Create Record' action in the flow designer and add the user along with the role selected to 'sys_user_has_role' table. Prior to which you have to evaluate the approval condition.

 

Regards

Sails
ServiceNow Consultant
United Kingdom

Chinmay Tawade1
Tera Guru

Flow Designer Steps - 

Step 1 - Get Catalog Variables.

ChinmayTawade1_1-1667822590532.png

 

Step 2 - Ask For Approval - Approval for Requested Fors Manager

ChinmayTawade1_0-1667822525263.png

Step 3 - If Approval.State = Approved

Step 4 - Create Record on sys_user_has_role table

ChinmayTawade1_2-1667822858932.png

 

Mark as helpful if this works for you,

 

Thanks

Chinmay

 

Hi @Chinmay Tawade1 ,

Similarly i am trying for roles to be added to group,. Role is created as list collector variable, but lookup is not working for list collector what should i do.

Preethi26_0-1701146318334.png

 

First thing is - a record must be created on sys_group_has_role table for each role.

so thats the reason you cannot add multiple roles(list collector) into one record.

 

I have created a flow and custom action to add roles to group.

 

Catalog item with variables - Group(reference) and Roles(List Collector)

ChinmayTawade1_0-1701151854297.png

 

Below is the flow

ChinmayTawade1_1-1701151934254.png

Step 1 - Get catalog variables

Step 2 - Custom action to convert list collector roles value to array of string (bcause we cannot loop though list collector value so need to convert it to array of string)

ChinmayTawade1_2-1701152122050.png

Step 3 - For each loop on Array of Roles from step 2 custom action

Step 4 - create sys_group_has_role record for each list collector group

ChinmayTawade1_3-1701152240335.png

 

In this way you will first need to process/convert the list collector roles value to Array and then apply for each on that array, and create record for each role. You cannot add all roles to one group role record, you need to create individual record for each role.

 

Please Mark as helpful, if this resolves your problem.

 

Thanks,

Chinmay Tawade

ServiceNow Developer