- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2015 11:31 AM
Wondering if anyone has done anything with regards to dynamically handling the number of approvals in a single workflow. The idea is that something needs to go through a series of inline approvals, meaning each approval is created after the previous one has been approved, yet the number of approvals is dynamic based on various conditions of what's being requested.
So, one request may require two approvals yet another request may require four approvals. Again, the approvals must be inline so I don't believe I can use a group-type approval activity since all approvals would be sent at the same time.
My idea so far is to add several approval activities to the workflow and use them as placeholders. For example, I would add 10 approval activities to the workflow but only use two of them if the request required two approvals, or use four of them if the request required four approvals. The drawback to this approach is if the request required more approvals than there are placeholders.
Any other ideas?
Thanks,
Michael
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2015 08:51 AM
I appreciate all the replies buy my issue is not dynamically adding one or more approvers to a single Approval workflow activity. What I'm looking for is a way to dynamically add sequential approvals. That is, approval #1 must be approved before approval #2 is sent, and #2 must be approved before #3 is sent and so on. The key is the number of approvals must be dynamic, for example, one request may only require 2 approvals whereas another request may require four approvals - again, in sequence not in parallel.
So I turned to a ServiceNow friend, Dave (Super Dave) Knight and he pointed me to the ServiceNow Document Management Application (requires a plugin activation) which already has this dynamic sequential approval feature in place.
Here's how it works (courtesy of Super Dave):
There is a list of approvers at the bottom of the form, arbitrary length. There is also a field on each approver called 'Sequence'. If you are #1, you approve first. If you are #2, second, and so on. Better yet, if two people are at #2, they approve in parallel, after #1 approvers, and before #3. You get the picture.
There is a workflow built to handle that. It is designed to iterate approvals through that list. It is called 'Document Management Default', illustrated below. It uses a standard Approval activity (scripted of course), and a loop. I've included the code in the key activities marked 1, 2 and 3 below (in case you do not have the document management plugin installed).
Activity #1 (Run Script): Basically goes to the list of records in the DB and remembers the who and sequence number for each value in RAM (the scratchpad). The code that gets the list out of the DB is in DocumentManagementDB, but as you will see, all it does is create an array of approvers, where each object has the name and sequence number of the approver.
current.approval = 'requested';
var db = new DocumentManagementDB();
var approvers = db.getApprovers(current.document);
workflow.scratchpad.approvers = approvers;
if(approvers.length>0){
workflow.scratchpad.current_sequence = approvers[0].sequence;
} else {
workflow.scratchpad.current_sequence = 0;
}
Activity #2 (Approval — User, Additional approvers script): This just gets the array of all approvers at the current sequence number …
answer = [];
var currentSequence = workflow.scratchpad.current_sequence;
var approvers = workflow.scratchpad.approvers;
for(var i=0; i<approvers.length; i++){
if(approvers[i].sequence == currentSequence) {
if(approvers[i].user){
answer.push(approvers[i].user);
} else {
answer.push(approvers[i].group);
}
}
}
Activty #3 (If, Script):
answer = isThereANextSequence();
function isThereANextSequence() {
var currentSequence = workflow.scratchpad.current_sequence;
var approvers = workflow.scratchpad.approvers;
var nextSequence = getNextSequence(approvers, currentSequence);
if (nextSequence>0) {
workflow.scratchpad.current_sequence = parseInt(nextSequence);
return 'yes';
}
return 'no';
}
function getNextSequence(approvers, currentSequence){
for(var i=0; i<approvers.length; i++){
if(approvers[i].sequence>currentSequence){
return approvers[i].sequence;
}
}
//We went through all the sequences
return 0;
}
I know I'm going to find many uses for this functionality and I hope others find it useful as well.
Once again, many, many thanks to Dave Knight for this information.
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2015 03:44 PM
I am running into a same issue.
I created one Approval-user in the Workflow and checking the count in IF condition after this task.
But the problem is when I go back and set the user, the same approval task is getting rewritten by the new user. So in effect, it looks like it went through just one level of approval.
Please let me know if any one finds a solution for this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2015 11:43 PM
Hi Michael,
You can use Advanced Group Approval activity where you can conditionally add dynamic approval, if there is no approval that activity will be skipped.
Please refer Handling Dynamic Approvals for more information.
if(Condition 1)
{
answer.push('id1');
answer.push('id2');
}
else if(Condition 2)
{
answer.push('id1');
answer.push('id2');
answer.push('id3');
}
else
{
answer.push('');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2020 05:42 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2015 08:51 AM
I appreciate all the replies buy my issue is not dynamically adding one or more approvers to a single Approval workflow activity. What I'm looking for is a way to dynamically add sequential approvals. That is, approval #1 must be approved before approval #2 is sent, and #2 must be approved before #3 is sent and so on. The key is the number of approvals must be dynamic, for example, one request may only require 2 approvals whereas another request may require four approvals - again, in sequence not in parallel.
So I turned to a ServiceNow friend, Dave (Super Dave) Knight and he pointed me to the ServiceNow Document Management Application (requires a plugin activation) which already has this dynamic sequential approval feature in place.
Here's how it works (courtesy of Super Dave):
There is a list of approvers at the bottom of the form, arbitrary length. There is also a field on each approver called 'Sequence'. If you are #1, you approve first. If you are #2, second, and so on. Better yet, if two people are at #2, they approve in parallel, after #1 approvers, and before #3. You get the picture.
There is a workflow built to handle that. It is designed to iterate approvals through that list. It is called 'Document Management Default', illustrated below. It uses a standard Approval activity (scripted of course), and a loop. I've included the code in the key activities marked 1, 2 and 3 below (in case you do not have the document management plugin installed).
Activity #1 (Run Script): Basically goes to the list of records in the DB and remembers the who and sequence number for each value in RAM (the scratchpad). The code that gets the list out of the DB is in DocumentManagementDB, but as you will see, all it does is create an array of approvers, where each object has the name and sequence number of the approver.
current.approval = 'requested';
var db = new DocumentManagementDB();
var approvers = db.getApprovers(current.document);
workflow.scratchpad.approvers = approvers;
if(approvers.length>0){
workflow.scratchpad.current_sequence = approvers[0].sequence;
} else {
workflow.scratchpad.current_sequence = 0;
}
Activity #2 (Approval — User, Additional approvers script): This just gets the array of all approvers at the current sequence number …
answer = [];
var currentSequence = workflow.scratchpad.current_sequence;
var approvers = workflow.scratchpad.approvers;
for(var i=0; i<approvers.length; i++){
if(approvers[i].sequence == currentSequence) {
if(approvers[i].user){
answer.push(approvers[i].user);
} else {
answer.push(approvers[i].group);
}
}
}
Activty #3 (If, Script):
answer = isThereANextSequence();
function isThereANextSequence() {
var currentSequence = workflow.scratchpad.current_sequence;
var approvers = workflow.scratchpad.approvers;
var nextSequence = getNextSequence(approvers, currentSequence);
if (nextSequence>0) {
workflow.scratchpad.current_sequence = parseInt(nextSequence);
return 'yes';
}
return 'no';
}
function getNextSequence(approvers, currentSequence){
for(var i=0; i<approvers.length; i++){
if(approvers[i].sequence>currentSequence){
return approvers[i].sequence;
}
}
//We went through all the sequences
return 0;
}
I know I'm going to find many uses for this functionality and I hope others find it useful as well.
Once again, many, many thanks to Dave Knight for this information.
Michael

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2015 08:43 PM
This is a great way to handle approvals, could help in multiple scenarios.