Show Table of Contents
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
processInstancevariable 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 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 variablename.
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.24. Script Editor
When a script for Java cannot be represented by this editor, it shows an alert like the following:
return true;

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.