if an approval user is inactive approver should be his manager instead of inactive users

pavan9885
Tera Guru

if an approval user is inactive approvals   should have to trigger for his manager instead of inactive user how to achieve this functionality. i want to achieve this functionality for global applications .

1 ACCEPTED SOLUTION

antin_s
ServiceNow Employee
ServiceNow Employee

Hi Pavan,



You may use the below code to find the approver in the management hierarchy if the current user is inactive.



var approver;


var count = 0;


var user = new GlideRecord('sys_user');


user.get('62826bf03710200044e0bfc8bcbe5df1');


if(user.active)


approver = user;


else


approver = getApprover(user, count);




gs.log(approver.name);




function getApprover(user, count){



if(count > 10)


return;



if(user.active)


return user;


else


return getApprover(user.manager, ++count);



}



Hope this helps. Mark the answer as correct/helpful based on impact.



Thanks


Antin


View solution in original post

7 REPLIES 7

antin_s
ServiceNow Employee
ServiceNow Employee

Hi Pavan,



You may use the below code to find the approver in the management hierarchy if the current user is inactive.



var approver;


var count = 0;


var user = new GlideRecord('sys_user');


user.get('62826bf03710200044e0bfc8bcbe5df1');


if(user.active)


approver = user;


else


approver = getApprover(user, count);




gs.log(approver.name);




function getApprover(user, count){



if(count > 10)


return;



if(user.active)


return user;


else


return getApprover(user.manager, ++count);



}



Hope this helps. Mark the answer as correct/helpful based on impact.



Thanks


Antin


Shishir Srivast
Mega Sage

Please check if this helps.



var user = new GlideRecord('sys_user');  


user.get(current.sys_id);  


if(user.active)  


return user.getValue('user_id');  


else  


return user.getValue('manager');  


Nitin_NOW
Tera Guru

Hi Pavan 

Did you ever got this sorted out? I'm actually stuck with the same issue. Could you please provide the BR for this if you have.

Thanks

pavan9885
Tera Guru

Hi Nitin you can use before update business rule on sysapproval table and use srivastav code it would help you and let me know if you still have issues.