It's entirely possible that a business process might be a straight line from start to finish. A series of steps that need to happen in order to produce a result. Quite often though, life becomes more complicated.
There will be occasions where branching paths are required. Perhaps a user needs to make a decision about what to do next, based on feedback from customers or equipment. There might be times when a process must go in one of two or more unique directions.
Whatever the reason for these branching paths, you'll need to get to know gateways before you can factor them into your processes. Once you've got a handle on them though, you can really start mapping in some incredible complexity into your processes.
How do you set up a gateway?
The first step to setting up a gateway is to add a gateway to your process. You can do this by either selecting an existing element in the process diagram and selecting the diamond shape from the popup options. Or, you can drag in a gateway from the toolbox.
From there you'll need to link your gateway to the tasks it will branch to. Do this by selecting the gateway and choosing the global connect tool (otherwise known as the arrows!) and then click on the element you need to connect. You can also select the global connect tool from your toolbox.
If the element you'd like to doesn't already exist, you can select the latest element in the process and from the pop-up, select the element you'd like to create. This will automatically link this new element with the previous one.
With everything placed and connected, it's time to start configuring your gateway.
What gateway should you use?
Gateways you place are automatically set as exclusive gateways. If you click the gateway and then the spanner icon, you can choose to change your gateway to either a parallel or inclusive gateway.
Each of these three options has their own usage. Lets take a look at the different options below so you can select the correct one when splitting the process. We will cover merging the process further down in this article:
An Exclusive Gateway means that the process will only continue in a single direction depending on conditions. If you’ve set this up after a User Task which includes a Select Option Field, you can choose which option the user selects as the logic behind which path will be taken and which element will be next in sequence, for example the next User Task
An Inclusive Gateway will allow one or more paths to be followed after the gateway, depending on conditions. This can be used if a variable number of actions need to occur depending on conditions as the Process continues
A Parallel Gateway allows for multiple different paths to be followed after the gateway in parallel. This gateway doesn't use conditions as each path following the gateway is valid
When mapping gateways, output paths with red dotted lines means you'll need to configure an expression for each path or set one to default. For most of the gateways you can select, you'll need to know about expressions.
What are expressions?
Expressions are about the closest you'll come to needing actual code to complete mapping your process, and they can looking daunting at first. But, rest easy. We have some great example expressions ready to be slotted in, and you can find many more examples of expressions over at the Camunda Expression Language Library.
Setting up expressions
Once you've placed your gateway, set up the paths leading from it, and configured it, you need to get into the nuts and bolts of the matter. As with all gateways, that means setting expressions.
For now, lets stick to the simplest form of expressions. When you select the path leading off your gateway, you'll be given a field you need to fill, and examples of how to fill it. We're going to take a look at field == 'true' for our gateway set up. If you click on this example, it will be automatically copied to the expression field.
By adding in this expression, you're telling Atlas Play that this pathway can be taken if the value of field is equal to true. If you're head's spinning, don't worry. We can break it down further.
Field is going to be replaced in this expression by a value set in a previous task. So, for example, if you have an option field in your previous task that asks the question 'Has the kettle boiled?' you will, by default, have two options to choose in the form of 'Yes' and 'No'. By default, these will correlate to true and false values.
So, you need to go to the previous task and copy the field key, which will be visible inside the the relevant field, noted as key. You can click the copy icon and head back to your expression. Delete 'field' and copy in your key. Make sure there is still a space between your key and the equals signs. So you should have, in this example, kettle_boiled == 'true'.
Now, this path will only be taken if the user selects the option with the true value when running the previous task. If your option has a value different from true, you can replace true in the expression with that value.
Congratulations! You've successfully configured your first expression. It goes without saying that we could delve much deeper into the sea of expressions, but for the time being, we have enough to be getting on with.
Best practice tip: It's best practice to make any field used in an expression "is required" to ensure it will hold a value.
NB: When using an OR expression for example, (format: field == 'SN0001' || field == 'SN0002'), if your process isn't a simple linear flow, be sure that both fields will have values before the point in the process where the expression is executed, for it to work.
This means that you need to set these values in a task BEFORE the expression is used.
How to set up an inclusive gateway
Select your gateway and select the inclusive gateway option, that's the diamond with the circle in it! For an inclusive gateway, the tasks following the gateway don't necessarily all need to be started.
For example, if your process is leading to making a coffee where the type of coffee is selected in the preceding task, with options such as black coffee, cappuccino, latte, and the following tasks are prepare coffee and prepare milk.
For all coffee type options the prepare coffee task needs to run, but the prepare milk task only needs to run if coffee type is cappuccino or latte.
How to set up an exclusive gateway
Setting up an exclusive gateway will start just the same as setting up an inclusive gateway. Place down your gateway, relevant tasks, and link them up. The difference here is that only one of the branching paths will be taken.
This means that a decision in the task prior to your gateway will mean the user will only be given one of two or more tasks next in the process. For example, if you provide your user an option field with a true or false outcome, they will be given a task to run next based on their choice in the previous task.
For example, you might have the result from inspection of a part, which will either be Passed or Failed, which could be a user selection in the task before the gateway.
The path from the gateway if the inspection result is Passed could be onto a task to ship the part. The path in the case of inspection result Failed could be to return to rework the part. Only one path will be followed, depending on which expression is met
Your expressions should reflect that. The value and field that you select for each expression on the branching paths leading off from the exclusive gateway you've set up should match the options in a previous task, and the outcome you'd like to produce in terms of follow up tasks.
Best practice tip: On an exclusive gateway, especially where there are multiple outputs or complicated expressions, define one path with the default condition (effectively none of the other connection expressions have been met), to ensure a route out of the gateway will always be taken.
How to set up a parallel gateway
The parallel gateway setup remains the same as your other options, but this time you'll be providing the user with multiple tasks that can be run following the gateway. These tasks can be completed in any order and the process will continue until another gateway is chosen or the path returns to a single track.
Merging using gateways
Similar to how you use gateways to split processes into different paths, you can also use them bring a process back to fewer paths in a controlled way. As mentioned above, if the process can continue once one path has been completed, no gateway is necessary. You can just connect the different elements back to a common meeting point.
In this sense, gateways that merge a process back into a single path are a way of controlling the flow. Without a gateway, the moment any path reaches the merging point, the process will continue.
There's also the possibility that the process won't need to merge again. A process also continue on to one of multiple, distinct end points.
For example: after a splitting parallel gateway with a task on each path, to ensure all parallel tasks have been completed before proceeding to the next task on a process, a merging parallel gateway is required.
Or, after a splitting inclusive gateway, with a task on each path, to ensure all of the inclusive tasks that were triggered based on the current conditions are complete before proceeding to the next process task, a merging inclusive gateway is required.
Labelling your gateways
However you end up configuring your gateways, labelling them is a very useful practice and we suggest you do it each time you configure a new gateway.
To label a gateway, double click on the gateway and any paths leading from it. A textbox will popup, allowing you to enter text. Now you can label the gateway and each path accordingly. You can reposition the label if needed by clicking and dragging.
Doing this will help you or anyone else who comes to remap this process understand what's happening with your gateway, how and why.