Skip to content

Expression Language

Usage of Expression Language

Delegation Code

Two types of expressions are supported: camunda:expression and camunda:delegateExpression.

The camunda:expression can be used to evaluate a value expression or to invoke a method expression.

The following example shows several ways an expression can be used.

<process id=”process”>
    <extensionElements>  
      <!—Use expression to set process variable -->  
        <camunda:executionListener event=”start”  expression=”${execution.setVariable(‘test’, ‘foo’)}”/>  
    </extensionElements>
    <userTask id=”userTask”>  
        <extensionElements>  
      <!—Call method of a bean with current task as parameter -->  
            <camunda:taskListener event=”complete” expression=”$myBean.taskDone(task)}”/>  
        <extensionElements>  
    </userTask>
<!—Evaluate expression and save in a result variable -->  
     <serviceTask id=”serviceTask”   
                    camunda:expression=”${myBean.ready}” camunda:resultVariable=”myVar” />
</process>

ExpressionLanguage

The camunda:delegateExpression can be used for expressions which evaluate to a delegate object. This object must implement either the JavaDelegate or ActivityBehavior interface.

<!—Expression that calls a bean implementing the JavaDelegate interface -->
<serviceTask id=”task1” camunda:delegateExpression: “${testBean}” />
<!—Expression that calls a method which returns a delegate object -->
<serviceTask id=”task2” camunda:delegateExpression:  “${testBean.createDelegate()}” />

DelegateExpression

Refer Camunda Documentation link for more details.

Conditions

Expression Language can be used in conditional sequence flows to evaluate the condition and determine the outgoing sequence flow. This requires a conditionExpression element of the sequence flow with the type FormalExpression to be used. The text content of the element is the expression to be evaluated.

The following example shows the expression language used in a condition of a sequence flow.

<sequenceFlow>
    <conditionExpression xsi:type=”tFormalExpression”>
    ${test == false}
    </conditionExpression>
</sequenceFlow>

ConditionExpression

Refer Camunda Documentation link for more information on Conditions.

InputOutput Parameters

The inputParameter or outputParameter of the inputOutput extension element can be mapped with expression language.

The following example shows an inputParameter with an expression that calls a method of a bean.

<serviceTask id=”task” camunda:class=”org.camunda.bpm.example.SumDelegate”>
    <extensionElements>
        <camunda:inputOutput>
            <camunda:inputParameter name=”x”>
                ${testBean.calculateX()}
            </camunda:inputParameter>
        </camunda:inputOutput>
    </extensionElements>
</serviceTask>

InputParameter

Refer Camunda Documentation link for more information on InputOutput Parameters.

Availability of Variables and Functions Inside Expression Language

Process Variables

All process variables of the current scope are directly available inside an expression.
The following example shows that a conditional sequence flow can directly check a variable value:

<sequenceFlow>
    <conditionExpression xsi:type=”tFormalExpression”>
        ${test ==  ‘start’}
    </conditionExpression>
</sequenceFlow>

Internal Context Variables

Depending on the current execution context, special built-in context variables are available while evaluating expressions.
The following example shows an expression that sets the variable test to the current event name of an execution listener.

<camunda:executionListener event=”start”  expression=”${execution.setVariable(‘test’, execution.eventName)}” />

Refer Camunda Documentation link for more information.

Internal Context Functions

Special built-in context functions are used while evaluating expressions.
The following example sets the due date of a user task to 3 days after the creation date of the task.

<userTask id=”theTask” name=”Important task”  camunda:dueDate=”${dateTime().plusDays(3).toDate()}” />

Refer Camunda Documentation link for more information.

Example BPA - (Validate age variable)

Validate Age