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

Hi Pavan 

I tried that already but no luck. Also it should be a Before Insert rule instead of before update, isn't it? Because it should check the user status before the approval record is created in the instance.

Thanks

Nitin_NOW
Tera Guru

Never mind I have sorted it out. If anyone is looking for the same rule, please find the below.

 

Before Insert Business Rule

Table: sysapproval_approver

Script:

var appr = current.approver.sys_id;

//gs.log('The approver--> '+appr);


var gr = new GlideRecord('sys_user');


gr.addQuery('sys_id', appr);


gr.addQuery('active', false);


gr.query();


if(gr.next()) {

var mgr = gr.manager;


current.approver = gr.manager;


//gs.log('The final manager--> '+mgr);

}

Thanks

Thanks for sharing your solution!

For Nitin BR use before BR with insert.