How to create Approval Sub Flow with a script in Flow Designer?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2022 04:10 PM
I'm trying to convert my Workflows to Flow Designer and I want to use Sub Flows for repeatable actions.
In most of our Service Catalog workflows, we require departmental approval before we fulfill the request. Since the approval is based on who requested the item and what department they are in, we have added a script to the workflow approval step. I cannot figure out how to do that in Flow Designer and would like some help.
Our Workflow approval step looks like this:
How do I translate the above into this? I don't see how I can add the approval group and the script with Flow Designer. And I do want it to be a sub flow so I don't need to add the same steps to multiple flows.
- Labels:
-
Flow Designer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2022 02:33 PM
No, that doesn't work.
If you look at my screen shots from the workflow, it's a normal approval but there is a script that determines the list of who can approve. That's what I'm stuck on. I can't figure out how to pass the approver list to the action in flow designer.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2022 05:06 AM
Hi
Well, yes that example I gave does not look at any departmental approval or something like that.
It just gives you the idea on how to add approvers by scrpipt in Flow Designer.
In my example, you need to replace the sys_id in line 7 with the sys_id of the user that needs to be the approver.
If you need more that one approver, put them all in the criteria.
The example just creates an approval for ONE fixed user.4
For your case, you obviously already have a script, which determines the Sys_IDs of all approvers.
So, you should be able to put those things together.
Does that makes sense to you?
Just let me know.
BR
Dirk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2022 06:36 AM
Hi,
What I have understood based on the condition you have mentioned is as below:
"Based on Requested For Department, an approval gets routed to that Department group and you need to design a reusable Sub flow to be used in other flows for different catalog item"
If the above understanding is correct then please follow the steps to achieve your requirement:
1) I would suggest you can create a Custom Action here and can re use it the way you want in multiple items:
Click on New and select "Action" under New as shown below:
Now click on Input and create a New input for this action as shown below:
Now within this input step click on (+) and then select Create Record as shown below:
Now for Assignment Group use the script below as shown :
/*
**Access Flow/Action data using the fd_data object. Script must return a value.
**example: var shortDesc = fd_data.trigger.current.short_description;
**return shortDesc;
*/
var getRequestFor = fd_data.action_inputs.requested_item.requested_for;
var getDepartment = fetchDepartment(getRequestFor);
var getApprover = getDepartmentApprover(getDepartment);
return getApprover;
function fetchDepartment(requestedFor){
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',requestedFor);
gr.query();
if(gr.next()){
return gr.department.toString();
}
}
function getDepartmentApprover(deptID){
var arr= [];
var gr1 = new GlideRecord('cmn_department');
gr1.addQuery('sys_id',deptID);
gr1.query();
if(gr1.next()){
arr.push(gr1.FIELD.toString());
}
return arr.toString();
}
Now make sure to Save and Publish this Action and then use it in your Flow where you want which will look for Requested for department and generate Group Approval dynamically.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke