Parallel Flow Launcher Activity on Catalog Items
Recently, I worked on the Parallel Flow Activity which works like a charm. I was using a catalog item i.e. sc_req_item table and calling multiple sub flows. I couldn't find lot of information on it so I am writing this post so that others find it useful. The situation I came across was on a catalog item which had to make multiple rest calls and each rest call could have its own separate workflow involving tasks and error logs etc. Having its own subflow makes it reusable for other workflows. Initial documentation which is a very good starting point is linked here below:-
While using Parallel Flow Launcher either you could call the same workflow multiple times by giving it a series of inputs or call multiple workflows based on conditions within your form.
If you are using a single workflow, I believe it is straightforward as choosing the workflow in the workflow selection and adding the inputs as an array. The number of inputs would determine the number of subflows that get generated. To get the input values into your sub flow you would have to edit inputs add a new input with the same key as below and define a column type accordingly.
But if you are wanting to use multiple workflows, you would have to click the Advanced checkbox and create the coordinator object :-
So within the Workflow field, you can add the following script as shown in the screenshot. Workflow1 and Workflow2 are the name of the Workflows you would like to call.
Code
coordinator = new WorkflowCoordinator( {workflow:'Workflow1'} );
var gr = new GlideRecord("sys_group");
gr.addQuery("name", current.variables.group_name);
gr.addQuery("manager", current.variables.manager);
gr.query();
while(gr.next()) {
coordinator.add( {groupId: gr.sys_id+ ''} );
}
coordinator.add( {u_application_name : current.variables.v_application}, 'Workflow2' );
coordinator; // THIS MUST BE THE LAST LINE
In the above script, I add the workflows to the coordinator object to trigger the subflows.
All the variables in the catalog item are available to the sub flow as workflow.inputs.variable_name.
Although the current object is available in the subflows, current.variables is not available. So you would have to use workflow.inputs to get the variables. If you want to create a task within your subflows and you plan to use the same subflows again from the parallel flow launcher it is important to have the task creation within a Run Script activity. In fact, i would suggest to create Task using Run Script to make it more versatile.
Once your subflows are complete, you can have a return value activity in your sub flow to process the output in the Variables Parallel Flow Launcher script. In mycase I pass either true or false from my subflows to check if it was successfully completed or not. I check for the flow outputs in the parallel flow launcher of parent workflow and take further actions based on it. I can a success or a failure to a scratchpad variable that can be used to regulate further flow in the parent workflow.
var flowOutput = [];
var flowCount = coordinator.getNumFlows();
if(flowCount) {
for(var index= 0; index < flowCount; index++) {
flowOutput.push(coordinator.getFlow(index).output);
}
}
if(flowOutput.indexOf(false) == -1) {
workflow.scratchpad.returnProcessedValue = "Success";
} else {
workflow.scratchpad.returnProcessedValue = "Failure";
}
I found this workflow activity to be pretty useful and since we all use catalog items a lot, leveraging this feature would be beneficial.
https://www.servicenow.com/community/developer-articles/parallel-flow-launcher-activity-on-catalog-items/ta-p/2328214