User is created when we select any department then ITIL should be added

Ankammarao
Tera Contributor

User is created when we select any department then ITIL should be added

1 REPLY 1

Craig Evans
Tera Contributor

There isn't much information to go off based on your question.

 

I assume that the user is created and when an admin/user_admin applies a department the role should automatically be added.

 

I would suggest using a before update business rule. 

 

Table - Sys_User

Condition - Department ISNOTEMPTY
Script - 

 

var usrRole = new GlideRecord('sys_user_has_role');

usrRole.initialize();

usrRole.user = current.sys_id;

usrRole.state = 'active';

usrRole.role = <SYS_ID OF ITIL ROLE>

usrRole.insert();

 

This would automatically apply the itil role to any user if the record is updated so that the department field is populated. I would suggest adding some additional validation to ensure that this does not run on users who already have the itil role.