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

Robbie
Kilo Patron
Kilo Patron

Hi @1dusjhyahnt,

 

I've checked your script on a vanilla Personal Dev Instance via a Background script, and it looks to work as intended. I've substituted the 'current.variables.requested_for' with the sys_id of good old user abel.tuter - See below and test/run this via 'Scripts - Background'.

 

Have you confirmed your script returns the sys_id where you're using the line: 'current.variables.requested_for' ?

 

I'd also recommend and guide you to best practice and not add a role to an individual user/users, instead, add the users to a group where the users inherit the role/roles via group membership.

 

To help others, please mark correct and helpful.

 

Thanks,

Robbie

 

var itil = new GlideRecord('sys_user_has_role');
itil.initialize();
// abel.tuter sys_id: 62826bf03710200044e0bfc8bcbe5df1
itil.user = '62826bf03710200044e0bfc8bcbe5df1'; // 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();