Dynamic Role creation?

Srvs
Kilo Guru

Hi All,

i have a level field, depends on level is it possible to allocate the role dynamically without creating the group??

i dont want to create a group and assign the role to group, i need to allocate the role depends upon level is it possible?

please help me in this scenario.

Regards

Venkat.

3 REPLIES 3

Gaurav Bajaj
Mega Sage

Hi Venkat,



You can try adding a business rule on sys_user table.


As soon as a record is set and level is added there, you can pick the level value and decide which roles you need to add to the user,



Just Query down sys_user_has_role table and try below script in the BR.




var gr = new GlideRecord('sys_user_has_role');


gr.initialize();


gr.user=current.sys_id; //sys_id of the user


gr.role="add sys_id of the role";


gr.state='active';


gr.insert();





Please mark the response correct/helpful based on the impact.




Thanks


Gaurav


Thanks @Gaurav Bajaj , It helped for me ðŸ™‚

AnubhavRitolia
Mega Sage

@Srvs 

 

Is your Level field on User table?

Also you want to implement it for Existing Users with Level value or for User when Level is updated?

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023