- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2015 12:03 PM
Hi,
I have an interesting requirement for approvals for one of our HR Change Requests. Basically, the approval chain should start at the user's manager's manager and continue until the Approver's title is "President & CEO". So basically we need approval from everyone up the chain, but we don't want to bother the President. I have been trying and failing to get this right.
Here's what I have so far. It seems to only grab the first user from the array that is returned.
// Set the variable 'answer' to a comma-separated list of user ids and/or group ids or an array of user/group ids to add as approvers.
var approver = current.variables.user.manager.manager;
answer = getAllApprovers(approver);
workflow.scratchpad.approver = answer;
gs.log('Scratchpad' + workflow.scratchpad.approver);
function getAllApprovers(user) {
var myApprovers = user;
if (user.title != 'President & CEO') {
gs.log(user.name + ' ' + user.title);
myApprovers += ',' + user;
getAllApprovers(user.manager);
}
return myApprovers;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2015 01:13 PM
It might be that when the function calls itself, it loses the myApprovers variable contents
Maybe try this:
var myApprovers = [];
var approver = current.variables.user.manager;
getAllApprovers(approver);
workflow.scratchpad.approver = myApprovers;
gs.log('Scratchpad' + workflow.scratchpad.approver);
function getAllApprovers(user) {
if (user.title == 'President & CEO') {
return false;
} else {
gs.log(user.name + ' ' + user.title);
myApprovers.push(user);
getAllApprovers(user.manager);
}
}
There are other examples of recursive functions int other business rules for CIs that might help here too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2015 01:13 PM
It might be that when the function calls itself, it loses the myApprovers variable contents
Maybe try this:
var myApprovers = [];
var approver = current.variables.user.manager;
getAllApprovers(approver);
workflow.scratchpad.approver = myApprovers;
gs.log('Scratchpad' + workflow.scratchpad.approver);
function getAllApprovers(user) {
if (user.title == 'President & CEO') {
return false;
} else {
gs.log(user.name + ' ' + user.title);
myApprovers.push(user);
getAllApprovers(user.manager);
}
}
There are other examples of recursive functions int other business rules for CIs that might help here too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2015 08:26 AM
Mike,
I have a similar request to get an approval on a item starting with the direct manager then step up the chain of command until the manager's approval limit is met. I am able to step through the organization okay, but the past approvers are not being retained. Does your solution above retain the past approvers? I need the approval email notification that is sent out to each manager to list the past approvers as well.
Thanks,
Sarah