
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
First you will want to review the Ask for Approval Action from Flow and Scripted Approvals.
Use Cases:
I need to gather approval groups from the CIs in the Affected CI list and generate approvals for each. I also need to look at the Group to CI (cmdb_rel_group) table and find Groups that need to approve.
It should work just like the Approval Group functionality in Workflow where I can pass the string of groups and the activity will generate an approval for each. It should also only require one approval from each Group and reject if any member of any of the Group rejects.
Solution:
Create a Subflow (we want to make this reusable) to leverage Ask for Approval in Flow and use Scripted Approvals.
How to do this:
While I'm not going to detail creating a Subflow and getting data, you should use the concepts below to support the approval step.
- Create a Variable for your Flow (Approval Groups as an example)
- When you have your list of records containing the Group records, loop through them and set the Variable you created with the values
Example:
Overall Subflow
Looping through and setting your Variable
Sample code to set your Variable
var appr = fd_data._2__for_each.item.ci_item.change_control;
var apprgrp = fd_data.flow_var.approval_groups;
if(appr != '' && apprgrp.indexOf(appr)==-1){
if(apprgrp == ''){
return appr.toString();
}else{
return apprgrp + ',' + appr.toString();
}
}else{
return apprgrp.toString();
}
Once you have your data, you will need to setup the Ask for Approval in your Flow. This is where we can use the action and script it to perform like the Group Approval activity in Workflow.
When you setup Ask for Approval, if you will have other Approvals in the main Flow, set the Approval Field to something other than Approval as the value. This will prevent the record that the Flow is running against from setting the Approval to Approved after the action has completed. You can do an update to the target record in the main Flow and set the Approval value once you have finished all your approvals.
When setting the Rules via a script, you can refer to Scripted Approvals for your options. What the article doesn't tell you is how to do AND as an option. The answer is this format, "ApprovesAnyG[group sys id]&AnyG[group sys id]". You also can't just set the Group Sys ID to the string of Groups either. Otherwise in this scenario they are all treated as one Approval. That means one approval from any member of the various Groups would Approve the record for all. What we want is to replicate the Group Approval Workflow Activity where you could pass the string of Groups and treat them as their own Approval independent of the other Groups, but to also reject if anyone rejects. You can achieve this without scripting, however you have to code each group in the condition. That doesn't work for us since we have a string of Groups.
To achieve this you will use the following in the Rules script:
var grps = fd_data.flow_var.approval_groups.split(',');
var rgrps = fd_data.flow_var.approval_groups;
var rl = '';
for (var i = 0; i < grps.length; i++) {
if(rl == ''){
rl = 'ApprovesAnyG['+grps[i]+']';
}else{
rl = rl +'&AnyG['+grps[i]+']';
}
}
if(rl != ''){
rl = rl+"OrRejectsAnyG["+rgrps+"]";
}
return rl;
You can see we are taking our string of Groups from our Variable and building the Approval Rule. The last piece that we add to the Rule at the end is the Or option for rejecting if any of the Groups reject. This should work just like the Group Approval Workflow Activity now.
Example:
If you set the Approval Field value to something different so you can control how the target record is approved from the main Flow, you will want to add a new Variable and capture the Output. Then when the Subflow completes, you can use the Output to decide if you are going to Approve/Reject from the main Flow.
Example:
Summary:
There are many ways to accomplish things in ServiceNow and this is just one example. You could create your own custom Action in Flow, but this way we can just create an overall Subflow to do all the work for us. If you were looking to have the functionality of the Group Approval Workflow Activity in Flow, this is the solution I've come up with. Hopefully this is helpful.
- 5,147 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.