Skip to Content
Product Information
Author's profile photo Venugopal Chembrakalathil

Execute workflow tasks in parallel using SAP Workflow Management

Overview

I have explained about  Referenced Sub flow in my previous blog. Now SAP Workflow Management has introduced some new powerful capabilities enable developers to execute activities in parallel. So far developers could model only static number of parallel branches in a workflow. Use cases requiring dynamic number of parallel activities of the same type is possible now in SAP Workflow.

Use cases

For eg: Multiple Line items in a Purchasing document require approval based on line items  with different approvers.

A document needs to be reviewed or approved by multiple users in parallel depending on the requestor choice.

An investment approval request sends to multiple approvers of the same level in parallel and each approver needs to make a decision.

All the above use cases require dynamic number of parallel activities and after completion of these activities the workflow needs to continue to execute the next set of activities. The new parallel for each feature enable customers to implement above use cases. The referenced subflow feature enable developers to assign a collection from workflow context and each element in the collection will be used to create a new workflow instance as a child workflow.

Parallel Workflows

In the below workflow model, there are two approval steps. A cost center owner approval and group head approval. There could be multiple cost center owners based on number of items in the request or the same request needs to be approved by multiple cost center owners in parallel. Each item may be charged to a different cost center and the corresponding cost center owner need to approve the requested item. The Cost Center Owner approval is modeled as a referenced subflow and marked for parallel execution. The parent workflow will wait until all the referenced subflow workflow instances complete execution and continue with the next activity, Group Head Approval.

The below configuration shows how to model a reference subflow executing multiple workflow instances in parallel during runtime. The property Type needs to set as parallel. A collection based on number of workflow  instances required to be assigned to the Collection Context Path. This collection can be dynamically built in the workflow context using a scrip task or pass through workflow start. Each element in the collection will have an equivalent workflow instance. The completion condition is an optional property explained later in this blog.

Conditional Exit in Parallel Workflows

When you execute workflows in parallel using a Referenced Subflow, the next activity will be started after completion of all the workflow instances started. But there could be conditional exits where the Referenced Subflow need to terminate some of the parallel running workflow instances. for eg: in the above example, one of the cost center owners reject the request, the approval request is no more valid.

Completion Condition

A completion condition can be defined based on the status of a context variable from the referenced subflow instances. This status variable can be mapped in the output mapping. In the below example a completion condition is defined. The loop.counter is a standard variable enable access to the output mapping from each of the referenced subflow instances.

 

${context.CCApprovers[loop.counter].decision== "reject"}

The referenced subflow out put mapping receives the status variable “decision” from each of the referenced subflow instances.

If one of the parallel running subflow instance has status reject, the referenced subflow will complete the execution and continue the next steps.

Monitoring

SAP Workflow Management offers out of the box monitoring capabilities to keep track of all workflow instances. It is possible to navigate between the main workflow and referenced workflow instances providing a parent child view. This enables developers or administrators to easily manage the workflow instances belongs to a specific parent workflow.

Summary

The new par-for-each feature in Workflow Management improve the process performance by executing workflows in parallel without any additional synchronization logic developed and easy to monitor these instances using Monitor workflow applications.

SAP Workflow Management has released Boundary Events to raise escalation events from a referenced subflow. Please go through my next blog about how to consume Boundary Events in a referenced subflow.

 

 

Assigned Tags

      11 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Jerry Zhang
      Jerry Zhang

      Hi Venu,

      Thanks for this nice blog.

      I followed this blog and deployed workflow application to SAP BTP successfully. But there is an error in subflow instance(s) when testing.

      "The collection configuration '${context.CCApprovers}' of the loop could not be resolved to a valid collection."

      The initial context is as below.

      {
      ...
      "CCApprovers": [
      "User1",
      "User2"
      ],
      ...
      }

      Author's profile photo M.P. N.
      M.P. N.

      Hi,

      I got the same error. How did you solved this?

       

      best regards

       

      Mani

      Author's profile photo Rama Sulakshani Murari
      Rama Sulakshani Murari

      Hi Jerry,

      You can try something like below.

      var approversObject = [];
      var approvers = [];

      approvers = approversList.split(",");

      for(var i=0; i<approvers.length; i++) {

      var approversInfo = {

      name: "",
      decision: ""
      };

      approversInfo.name = approvers[i];
      approversObject.push(approversInfo);

       

      Thanks and Regards,

      Rama.

      Author's profile photo Rathish K
      Rathish K

      Hi Team,

      I am facing an issue in parallel subprocess. When I trigger a WF it spawns around 15 parallel subprocess. Every time, I see out of 15 subprocess 2 subprocess fails randomly and the log is as shown below. There is no completion condition set for the subprocess. Kindly help

      An unspecified error occurred. Contact support citing logId 86739823-e2bd-4e41-a851-2bdc005d2da8 and provide steps to reproduce.
      Log ID: 86739823-e2bd-4e41-a851-2bdc005d2da8

       

      Main-flow

      Main-flow

      Thanks
      Rathish
      Author's profile photo Venugopal Chembrakalathil
      Venugopal Chembrakalathil
      Blog Post Author

      Hi Rathish,

      Are you sure the collection you are assigning to the Ref Sub process has 15 objects.

      Is it possible for you to share the details of the collection you are assigning ?

       

      thanks

      Venugopal

      Author's profile photo Rakesh Singh
      Rakesh Singh

      Hi Venugopal,

      I have created a workflow and a sub workflow .In my case there are two item at run time( having different approvers for each item ).I follow your document parallel under Loop Configuration and is working fine and sending two task .

      But in sub workflow, I could not able to configure approver of each line item . Request you for your kind help .Thanks

      My approvers are in json file at the time of instantiating the main workflow .

      "SupData": {
      "SeconApprover1": "rak19@gmail.com",
      "SeconApprover2": "rak20@gmail.com"

      ++++++++++++++++++++++++++++

      {
      "buyerData": {
      "firstName": "Harsh",
      "lastName": "Patel",
      "Requester_mail_id": "rak19@gmail.com",
      "first_approver": "rak19@gmail.com",
      "address": "Gujarat" },
      "SupData": {
      "SeconApprover1": "rak19@gmail.com",
      "SeconApprover2": "rak20@gmail.com"
      }

       

      }

      Author's profile photo Venugopal Chembrakalathil
      Venugopal Chembrakalathil
      Blog Post Author

      Hi Rakesh,

      The loop determines the number of Ref Subflow instances. To pass the approver names, you need to assign them in the input mapping. The Collection you assign to the Collection context path  is not passed to the child subflow. Only the input mapping would be shared. So you can keep the approvers in a collection and do the input mapping using the loop.counter variable. for eg. SupData[loop.counter].approver

      thanks

       

      Venugopal

      Author's profile photo Rakesh Singh
      Rakesh Singh

       

      Thanks for your quick reply .

      In input mapping, I tried with multiple permutation & combinations.

      1. if i am passing below details

      Source :  ${context.SupData[loop.counter].SeconApprover1}

      Target :   ${context.Approveritem.RApprover}

      i am getting no approver

      {
      "Approveritem": {
      "RApprover": null
      }
      }

       

      2. if i am passing below details then both task it is going to same approver .

      Source :  ${context.SupData.SeconApprover1}

      Target :   ${context.Approveritem.RApprover}

       

       

      My approvers are rak19@gmail.com and rak20@gmail.com . In parallel processing one task should go to rak19@gmail.com and second task to rak20@gmail.com .

      "SupData": {
      "SeconApprover1": "rak19@gmail.com",
      "SeconApprover2": "rak20@gmail.com"

       

      Request you to please suggest .

       

      Author's profile photo Venugopal Chembrakalathil
      Venugopal Chembrakalathil
      Blog Post Author

      Hi Rakesh,

      context.SupData should be an array. As of now it is not.

      please refer this hands on guide.

      https://github.com/SAP-samples/teched2021-DEV164/tree/main/exercises/8_ExecuteWorkflowApprovalsInParallel

       

      thanks & regards

       

      Venugopal

      Author's profile photo Rakesh Singh
      Rakesh Singh

      Thanks a lot!

      Nice document . Its resolved my problem .

       

      Author's profile photo Christopher Linke
      Christopher Linke

      Hi Venugopal Chembrakalathil

      is it possible to have a "Completion Condition" such as IF 2 Sub-Workflow were approved, cancel the rest and come back?

      The idea is that we want to start the sub-Worflow for 10 Approvers, but we need the OK from 2 out of those 10. Whenever we got 2 approvals, we can go ahead

       

      Thank you,

      Christopher