4.13. Constraints
A constraint is a boolean expression that is evaluated when the element with the constraint is executed. The workflow depends on the result of the evaluation, that is true or false.
There are two types of constraints:
Code constraints, which are defined in Java or MVEL, and have access to the data in the working memory, including the global and process variables.Example 4.4. Java Code Constraint
return person.getAge() > 20;
Example 4.5. MVEL Code Constraint
return person.age > 20;
Rule constraints, which are defined in the form of DRL rule conditions. They have access to data in the working memory, including the global variables. However, they cannot access the variables in the process directly, but through the process instance. To retrieve the reference of the parent process instance, use theprocessInstancevariable of the typeWorkflowProcessInstance. 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, 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") ) )This rule constraint retrieves the process variable
name.
Red Hat 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.
Figure 4.22. Script Editor

When a Java script cannot be represented by the editor, the following alert appears:


Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.