How to send approval after finding active manager recursively ??
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2024 09:18 AM
I need to send dynamic approval to the requestor manager if requestor manager is inactive I need to check with his manager if he also in active need to check with his manager this should happen until I found active manager and approval should trigger.
any logic help?
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2024 04:55 AM
You can do this in a Workflow Approval - User activity script like this:
var mgr = current.opened_by.manager; //requestor's manager
//var mgr = current.variables.variable_name.manager; //using a reference variable to determine requestor
var mgrAct = false;
if (mgr.active){
answer.push(mgr.toString()); //requestor's manager is active, so generate the approval and exit script
mgrAct = true;
}
while (!mgrAct) {
var mgrGr = new GlideRecord('sys_user');
if (mgrGr.get(mgr)) {
if (mgrGr.manager.active) {
answer.push(mgrGr.manager.toString()); //this manager is active, so generate the approval and exit script
mgrAct = true;
} else {
mgr = mgrGr.manager.toString(); //run the GlideRecord again, retrieving this user
}
}
}
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2024 10:32 AM
Hi @Manikantahere ,
try this out
function findActiveManager(userID) {
var gr = new GlideRecord('sys_user');
if (gr.get(userID)) {
while (gr.getValue('manager') && !gr.manager.active) {
if (!gr.get(gr.getValue('manager'))) {
return ''; // returns empty string if the user doesn't have manager
}
}
return gr.getValue('manager') ? gr.getValue('manager') : ''; //returns the active manager if exists else returs empty value
}
return ''; // if the passed sysid of the user doesn't exist resturns the empty string
}
gs.print(findActiveManager('put d UserID here'));
Please mark the answer as helpful and correct if helped.
Regards,
Chaitanya