Using conditions and scripts

When you use 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 by 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 can designate one path; otherwise, it is possible to start a workflow but never conclude it if the conditions are never satisfied. It 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.

The workflow condition builder has a selection not available for rules called Script Conditions. It includes two components.
  • 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. You can enter a script that computes a value, which is then used by the expression. The script is similar to the script feature; however, it does not modify incident data. You must use Python 3 to write the script that retrieves the values.

The following example shows a condition that requires the use of the advanced scripting field. The example uses the Python 3 language.

Expression field.

res or incident.country == "Russia"

Advanced Scripting field.

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 = False

To avoid performance issues, keep your script as short as possible.

If you choose to have multiple conditions for your output path, determine how the conditions are to be satisfied as follows:
  • 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 you use complex expressions.
Use the following procedure to add a condition.
  1. Click the output connector of an inclusive or exclusive gateway as shown.
  2. Click the pencil icon to open the Condition Builder dialog box; for example,
  3. In the Condition Builder, enter a name for your condition. If possible, make the name descriptive of the result that makes the path True.
  4. Click Add new to enter one or more conditions.
  5. Enter the conditions as described previously then click Save when done.
  6. If you are adding a default flow, click the output connector of an inclusive or exclusive gateway then click the wrench icon.
  7. Click Default Flow to designate the connector as the default flow.
  8. Click Save or Save & Close when done with the workflow.