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.

The workflow condition builder has an additional selection, not available for rules, called Script Conditions. This 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. 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.

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, you should 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 using complex expressions.
To add a condition:
  1. Click the output connector of an inclusive or exclusive gateway as shown below. The surrounding text describes this graphic, which is a snap shot of the user interface.
  2. Click the pencil icon to open the Condition Builder dialog box; for example: The surrounding text describes this graphic, which is a snap shot of the user interface.
  3. In the Condition Builder, enter a name for your condition. The name should be descriptive of the result that makes this path True.
  4. Click Add new to enter one or more conditions. The surrounding text describes this graphic, which is a snap shot of the user interface.
  5. Enter the conditions as described previously then click Save when done.
  6. If adding a default flow, click the output connector of an inclusive or exclusive gateway then click the wrench icon. The surrounding text describes this graphic, which is a snap shot of the user interface.
  7. Click Default Flow to designate the connector as the default flow.
  8. Click Save or Save & Close when done with the workflow.