ITIL role automatically assign to user , when manager approve the request , please check my code ?

1dusjhyahnt
Tera Contributor

Script :- 

 

var itil = new GlideRecord('sys_user_has_role');
itil.initialize();
itil.user = current.variables.requested_for; // instead of u_requested_for add the variable name of the catalog request form
itil.role = '282bf1fac6112285017366cb5f867469'; //sys_id og the ITIL role record
itil.insert();

 

This Script i'm using but it's not working for me 

5 REPLIES 5

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @1dusjhyahnt 

 

https://www.servicenow.com/community/developer-forum/how-to-assign-any-role-automatically-depends-on...

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

chetanb
Tera Guru

As a best practice you should add user to a group rather than giving the role directly .
var gradduser = new GlideRecord("sys_user_grmember"); // group member
gradduser.initialize();
gradduser.setValue('group','group_sysid');
gradduser.setValue('user' ,'user_sysid');
gradduser.insert();

Agree with @chetanb  Dont assign role direct to user, add user in group and assign role. 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************