Use expressions on your gateways to automatically choose which way a process should go depending on the information in forms or instances. Expressions can be used on both inclusive and exclusive gateways. Expressions can be used on Exclusive and Inclusive Gateways.
Expressions are not added to the gateway itself, instead they are configured on the sequence flow(s) that are connected from the gateway. Best practice is to add a text label to gateways that are phrased as a question and to have text labels on each outgoing sequence flow where each sequence flow is phrased as an answer to the question. This makes it easy to understand what the choice is and which way the process will continue depending on the answer. The process will continue along the expression(s) that are true.
Expressions are written using a special syntax (see below)
Each expressions must result in a true or false result. For example:
- "The value of this field in this form is equal to 'Computer'"
- "The number in this field in this form is greater than 100"
It is possible to combine multiple questions, however, both must be true for the entire expression to be evaluated as true
- "The value in this field is equal to 'red' and the value of that field is equal to 'blue'"
You can use expressions on both exclusive and inclusive gateways. For an exclusive gateway the process will continue in only one way, and if more than one expressions is true, then the process will still continue in only one way and that will be the, randomly selected, first evaluated way. So be careful with your expressions and make sure only one at a time can become true for control of the path decision. If none of the expressions is true then the process will follow the, if defined, default way.
For an inclusive gateway the process will continue in all the paths with true expressions, and it will only follow the default way if none of the expressions are true.
How to add expressions on gateways
1. Open the settings for the sequence flow you wish to add an expression on
2. Click on Set in the section Expression. A new window is opened
3. Enter your expression for when that expression will be true, se below for expression examples
If you want to add expressions depending on form data you first need to know the DataID for the form, which is the name of your form template.
The second thing you will need is the fieldName, the string defined in the name setting for the form field.
NOTE: If you want to use data from a form template the name (DataID) of the template can't include spaces
The syntax is: instance.GetDataObject("DataID")["fieldName"] OPERATOR/PREFIX "Value to check against"
Operators & Prefixes
Operators for mathematical expressions:
- Equal: ==
- Not equal: !=
- More than: >
- Less than: <
- More than or equal: >=
- Less than or equal: <=
Operators for combinations of more than one expression:
- And - All expressions must be true: &&
- Or - At least one expression must be true: ||
- Check if a multi selection includes a value: .include?
- Convert to integer for mathematical expressions: .to_i
NOTE: Quotations around your values indicates a string (text) and no quotations indicates a number (integer)
If a field value is equal to something specific:
instance.GetDataObject("DataID")["fieldName"] == "Computer"
If a field value is less than or equal to something specific but numeric value:
instance.GetDataObject("DataID")["fieldName"].to_i <= 100
If a certain value of a drop-down, with multi selection, is selected
NOTE: If you have a single selection drop-down then the syntax is the same as a field value equal to something specific.
If a checkbox is selected
instance.GetDataObject("DataID")["fieldName"] == "on"
If a field value is equal to something specific AND a checkbox is selected
instance.GetDataObject("DataID")["fieldName"] == "Computer" && instance.GetDataObject("DataID")["fieldName"] == "on"
If you want to check if an attachment field is used
instance.GetDataObject("DataID").ContainsKey('fieldName') && (instance.GetDataObject("DataID")['fieldName'].include? ".")
NOTE: If you want to check against a value from a metadata field and you have a value list with key values, the Value to check against must be your key value.
Finding expression errors
Expressions can be complex and small details in the expression may be the difference of your expression working correctly or not. If an expression does not make your process follow the path that you expected it would you can check the process application Event Log for any errors that your process application encountered, including expressions that failed to run.
This information may be a little technical, but it gives you a good indication on what went wrong. If you need additional help solving your expression problem, don't hesitate to contact our support team and supply them with the error code. Sometimes it requires an expert to fully understand.
When to use expressions on Gateways
Expressions on gateways can be used to evaluate form data and choose different process paths depending on the form input, this can automate decision making and streamline the process.
Use Subprocess End State to Configure Gateways
This function allows you to configure which path a gateway will direct the workflow in based on which end state a previous sub process or call activity had, without writing an expression.
Every completed instance or sub instance has an end state matching the name of the end event that caused the instance to complete. These end states are selectable as options for configuring which way an inclusive or exclusive gateway will take after a sub process or call activity has been completed.
Here's how to configure it:
- Add an inclusive or exclusive gateway somewhere after a sub process or call activity in your process model. Model these sub processes/call activities so they have different possible end events and name these events.
- Double click the gateway and click the Use end state from process. Choose which process you wish to draw your end state from and don't forget to name your subprocess or call activity.
- Draw your connector paths out from the gateway and double click them and click the Chose end state for this sequence flow. Choose which end state you wish to have trigger each sequence flow.