Using conditions and scripts
When using exclusive and inclusive gateways, you define the conditions for the output paths. An output path is valid only when its condition is True. As with rules, a condition is a statement that checks a field for a value using an operator, such as equal to.
Alternatively, you can designate an output path as the default flow, which means this path is used when none of the other output path conditions are True. When a gateway has multiple output paths, you should designate one path; otherwise, it is possible to start a workflow but never conclude it if the conditions are never satisfied. This, in turn, can cause errors in the workflow and inconclusive results in the incident.
Defining a condition for an output path is the same as defining conditions for rules. You select a field, an operator then a value.
- Expression. A single expression that must evaluate to True or False. The expression can use a property value from the incident, task or workflow.
- Advanced Scripting Option. Allows you to enter a script that computes a value which is then consumed by the expression. This script is similar to the script feature; however, it does not modify incident data. Use standard Python language to retrieve values. In the Language field, determine whether to use Python 2 or 3 to evaluate the script.
The following example shows a condition that requires the use of the advanced scripting field. The example uses the Python 3 language.
res or incident.country == "Russia"from datetime import datetime, timedelta
now = datetime.now()
if (datetime.fromtimestamp(incident.create_date/1000) < (now - timedelta(days=3))) or incident.confirmed:
res = False
elif incident.owner_id == 7:
res = True
else:
res = FalseTo avoid performance issues, you should keep your script as short as possible.
- Select All to make the path True only when all individual conditions evaluate to true (they are AND’ed together).
- Select Any to make the path True when any one of the conditions is true (results are OR’ed).
- Select Advanced to define your own logical statement using the AND, OR, and NOT operators. You can also use their respective symbols, &&, || and !. For example, 1 OR (2 AND 3) means that condition 1 set to true makes the path True, and conditions 2 and 3 both set to true makes the path True. To avoid unexpected results, make sure to use parentheses when using complex expressions.
- Click the output connector of an inclusive or exclusive gateway as shown below.

- Click the pencil icon to open the Condition Builder dialog box; for example:

- In the Condition Builder, enter a name for your condition. The name should be descriptive of the result that makes this path True.
- Click Add new to enter one or more conditions.

- Enter the conditions as described previously then click Save when done.
- If adding a default flow, click the output connector of an inclusive or exclusive gateway then
click the wrench icon.

- Click Default Flow to designate the connector as the default flow.
- Click Save or Save & Close when done with the workflow.