4.13. Constraints

A Constraint is a boolean expression that is evaluated when the Element with the constraint is executed. The workflow continues depending on the result of the evaluation (true or false).
There are two types of constraints:
  • Code constraints are defined either in Java or MVEL. They have access to data in the working memory, including the Globals and Process variables.

    Example 4.4. Code constraint defined in Java

    return person.getAge() > 20;

    Example 4.5. Code constraint defined in MVEL

    return person.age > 20;
  • Rule constraints are defined in the form of BRMS rule conditions. They have access to data in the Working Memory, including the Globals. However, they cannot access the variables in its Process directly, but through the Process instance: to acquire the reference of the parent Process instance, use the processInstance variable of the type WorkflowProcessInstance. Note that you need to insert the Process instance into the Session and update it if necessary, for example, using Java code or an on-entry or on-exit or explicit action in your Process.

    Example 4.6. Rule constraint with process variable assignment

    import org.kie.api.runtime.process.ProcessInstance;
    import org.kie.api.runtime.process.WorkflowProcessInstance;
    ...
    processInstance : WorkflowProcessInstance()
    Person( name == ( processInstance.getVariable("name") ) )
    The rule constraint acquires the Process variable name.
JBoss BPM Suite includes a script editor for Java expressions; the constrain condition allows code constraints for scripts in Java as demonstrated by the editor below.
Script Editor for BPM Suite 6.0 constraints.

Figure 4.24. Script Editor

When a script for Java cannot be represented by this editor, it shows an alert like the following:
return true;