Flows for APEX: Creating Loops or Circular Flows in Your Process

 

It often feels like we are going round in loops at work!  We submit a piece of work for approval -- and it comes back for re-work, before it can be submitted again.  That IS part of the process.  So how do we model that in BPMN, and what are the issues in implementing this in Flows for APEX?

Let's take the example of getting a purchase order approved.  It's tempting to produce a simple process model where everything just gets approved.  The happy case...

Simple expense approval process

But then what happens if the claim gets rejected?  Usually this means that the employee needs to edit the details, or provide more receipts, or somehow change the submitted document.  So our first diagram doesn't model the real process.

Our Expense Claim now with a Edit Loop

We would expect that when the employee gets notification that his claim has been rejected, he will edit his claim and resubmit it.  So we can add a sequence flow arrow from the 'notify employee of rejection' process step back to our 'create expense report' task.

That seems very simple - are there any issues that we need to consider?

Every Loop Needs to End Eventually!

Like any loop, you need to think through any conditions to make sure that your loop will eventually exit - either from the employee giving up claiming First Class flights when they are only entitled to fly in Economy, or the  expense report finally getting approved.  If all of the tasks in your loop are automated steps, such as script tasks, you do need to check your logic so that they do eventually complete!

Are there any Restrictions in Looping with Flows for APEX?

The main restriction that you need to consider is that a loop which starts inside a parallel section of the process should not loop back to a task outside of the parallel section if you want the model to complete.  Parallel sections are created by either a Parallel Gateway or an Inclusive Gateway -- creating multiple forward paths from a gateway.

In this next diagram, we have a parallel section. The process flow splits at the opening Parallel Gateway (named 'Split'), then Task B and Task C can be executed in parallel.  The process recombines at the closing Parallel Gateway, named 'Merge').

Looping inside the Parallel Section is OK

 I've added a gateway ('loop?') after Task B -- and our process can happily execute Task B multiple times until 'Loop?' takes the 'no' path.  The two paths wait for each other at the closing gateway 'merge', and everything is fine.

In this next model, I've made the loop jump outside of the parallel section...

Looping outside the Parallel Section is not good.

Here, our loop takes us back to Task A.   When Task A completes for the second time, it will create a new Task B and Task C.  Each time the process goes around this loop, the process will get more complex.  The closing Parallel Gateway 'Merge' will get confused by this, and will not close and our process will never complete.  So this situation should be avoided!

And to avoid any confusion, this applies to Parallel and Inclusive Gateways.  An Exclusive Gateway only has a single path forward from the opening gateway, and so looping back to before the Exclusive Gateway is OK.

What about those Linter Warnings?

If you have read the manual and are listening to good practice, you will know that it's always a good idea to use the BPMN Linter before you save your Flow Diagram in the Flow modeler.  For those that haven't found this yet, that's the grey lozenge at the bottom of the Flow Modeler canvas.  

The BPMN Linter will give you a warning (yellow) that 'Incoming Flows do not Join' on your 'Create Expense Report' task.

The BPMN Linter shows a warning (which you can ignore).

You can safely ignore this warning - it's just pointing out that there are two different routes into this task.  Some BPMN practitioners would argue that you should add a joining gateway in to solve this, as in this diagram.

You can add a gateway here to make the Linter happy - but it's not required.

You don't need to do this - it's a matter of personal style.  I personally wouldn't do this on my models because it's not necessary and I think that it adds unnecessary clutter to your model.   Flows for APEX is quite happy, whichever choice you make.

Comments

Popular posts from this blog

Flows for APEX - Changing Colours on the BPMN Viewer APEX Plug-In