How to assign role automatically for imported users?

swathigangadhar
Tera Expert

How to assign role automatically for imported users? I scheduling a job to run to import new users every week and i want to assign role 'end_user_new' to these users automatically, how to do that?

1 ACCEPTED SOLUTION

Hi,



I also suggest you tag the role to a group and add user in the group which is the best practice.



if(action =="insert"){


  var gr = new GlideRecord('sys_user_grmember');


  gr.initialize();


  gr.user = target.sys_id;   //After new user is inserted


  gr.group = 'sys_id_of_group';   // Tag the role to a group & add users in group


  gr.insert();


}





Thanks


PS: Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

9 REPLIES 9

Alikutty A
Tera Sage

Hi,



In your transform map, write an onAfter script and assign end_user_new role once the user is inserted.






Thanks


PS: Hit like, Helpful or Correct depending on the impact of the response


Hi,



I also suggest you tag the role to a group and add user in the group which is the best practice.



if(action =="insert"){


  var gr = new GlideRecord('sys_user_grmember');


  gr.initialize();


  gr.user = target.sys_id;   //After new user is inserted


  gr.group = 'sys_id_of_group';   // Tag the role to a group & add users in group


  gr.insert();


}





Thanks


PS: Hit like, Helpful or Correct depending on the impact of the response


Hi alikutty,



You are telling i need to write transform script, to add user to a group?


Yes and you should add the role to this group, This will help in maintenance. It is not a best practice to directly tag roles to a user.




Thanks


PS: Hit like, Helpful or Correct depending on the impact of the response