Parallel Flow Launcher and WorkflowCoordinator

Uncategorized,

The WorkflowCoordinator object is poorly documented (surprise, surprise), but it’s quite simple to use. I had never used it before, but got lucky and was able to get it working with minimal effort. The issue I need to solve was that an unknown number of approvals were needed for a particular catalog item. The number of approvals was based on the selected choices in a GlideList variable. Each of those options may or may not have its own approvals, including the same approver receiving multiple of them. The final piece of the requirement is that an approver could approve one item and reject another; a single approval could not apply to all approvals for a given approver.

I was stumped on how to address this issue. I thought I could just loop through a workflow activity multiple times and generate the approvals, etc., that were necessary. Workflow doesn’t behave the way I wanted it to, though. The issue was that the approvals at this point are related to the requested item, so Bob the Approver can’t have multiple approvals. I made the decision to have each of the approvals be against a unique catalog task that only facilitated and documented the approval.

In comes Parallel Flow Launcher

I was sure that something could help me more than a Run Script or Turnstile activity. I decided to look into the Parallel Flow Launcher activity via Product Docs. Honestly, that looks highly complicated and a bit more than I wanted to get into. (It turns out that it was exactly what I needed, but I have a bit more complaining to do first.) The Workflow Coordinator Object page didn’t help me much. This, to me, is a perfect example of a Product Docs article being woefully insufficient for the subject at hand. I checked the Developer site, but that came up empty:

API? More like LOL.
This is just messing with me, right? Product Docs DEFINITELY has more than zero results. (I linked to one above.)

Off to Community. This might be a niche subject in an outdated piece of the platform, but surely someone else has had questions about this and received insightful answers. Finally, I encountered this article, which helped with the proper formatting: Workflow Coordinator Object – What it is and how to use it in Parallel flow launcher workflow activity to dynamically call multiple subflows based on a condition (hell of a title and pretty much exactly what I was thinking at the time).

The use case in that Community article is sufficiently different from what I needed to do, but seeing a working example allowed me to formulate a solution. Here’s how I did it:

  1. Stage the data (an array of objects) in the workflow scratchpad via a Run Script activity
  2. Pass the data to the Parallel Flow Launcher, which would trigger a subflow (generating catalog tasks) as many times as needed
    1. The subflow sets a new string field on the sc_task table called “u_workflow_util” to one of the stringified objects in the array. That will be used in the next step.
  3. Yet another workflow, this time on Catalog Task, that would handle the approvals.
    1. The u_workflow_util value is returned to JSON to leverage in the approval activity as well as some AD Orchestration activities.

The sc_task workflow is there because any approvals on the subflow in step 2 would be on the requested item, not the catalog task. This is NOT an elegant solution, but it’s functional.

Step 1 – Stage the Data

Here’s the code I used to stage the data:

var wfcoordarray = [];
for (var i = 0; i < workflow.scratchpad.groupIDsForApproval.length; i++) {
	var a = {"group_id": workflow.scratchpad.groupIDsForApproval[i], "user_id": current.variables.requested_for + '', "request_item": current.getUniqueValue(), "group_name": workflow.scratchpad.groupNameArrayApproval[i]};
	wfcoordarray.push(a);
}
workflow.scratchpad.wfcoordarray = wfcoordarray;

Step 2 – Parallel Flow Launcher

There’s nothing fancy here except pulling into the input field the wfcoordarray from the scratchpad.

Step 3 – Catalog Task Workflow

workflow.scratchpad.input_obj = JSON.parse(current.u_workflow_util);

This is far from a “missing manual” post… ServiceNow should rectify that themselves. It does allow me, however, to put another working example of Parallel Flow Launcher and WorkflowCoordinator out in the world. I’m aware that I didn’t actually use WorkflowCoordinator, but it’s necessary to know how it works to use Parallel Flow Launcher activities.

Did I miss something in this process that would have simplified the solution? Is there another mechanism you have used to achieve the same goal, but in a significantly different way?

Leave a Reply