Specifying a class that implements a JavaDelegate or ActivityBehavior
Evaluating an expression that resolves to a delegation object
Invoking a method expression
Evaluating a value expression
To specify a class that is called during process execution, the fully qualified classname needs to be provided by the
camunda:class
attribute.
<serviceTask id="javaService"
name="My Java Service Task"
camunda:class="org.camunda.bpm.MyJavaDelegate" />
Please refer to the Java Delegate section of the User Guide for details on how to implement a Java Delegate.
It is also possible to use an expression that resolves to an object. This object must follow the
same rules as objects that are created when the camunda:class
attribute is used.
<serviceTask id="beanService"
name="My Bean Service Task"
camunda:delegateExpression="${myDelegateBean}" />
Or an expression which calls a method or resolves to a value.
<serviceTask id="expressionService"
name="My Expression Service Task"
camunda:expression="${myBean.doWork()}" />
For more information about expression language as delegation code, please see the corresponding
section
of the User Guide.
It is also possible to invoke logic which is implemented in form of webservices. camunda:connector
is an extension that allows calling REST/SOAP APIs directly from the workflow. For more information about using connectors, please see the corresponding section of the User Guide
Generic Java Delegates & Field Injection
You can easily write generic Java Delegate classes which can be configured later on via the BPMN 2.0 XML in the Service Task. Please refer to the Field Injection section of the User Guide for details.
Service Task Results
The return value of a service execution (for a Service Task exclusively using expressions) can be assigned to an already existing or to a new process variable by specifying the process variable name as a literal value for the camunda:resultVariable
attribute of a Service Task definition. Any existing value for a specific process variable will be overwritten by the result value of the service execution. When not specifying a result variable name, the service execution result value is ignored.
<serviceTask id="aMethodExpressionServiceTask"
camunda:expression="#{myService.doSomething()}"
camunda:resultVariable="myVar" />
In the example above, the result of the service execution (the return value of the doSomething()
method invocation on object myService
) is set to the process variable named myVar
after the service execution completes.
Result variables and multi-instance
Note that when you use camunda:resultVariable
in a multi-instance construct, for example in a multi-instance subprocess, the result variable is overwritten every time the task completes, which may appear as random behavior. See camunda:resultVariable for details.
External Tasks
In contrast to calling Java code, where the process engine synchronously invokes Java logic, it is possible to implement a Service Task outside of the process engine’s boundaries in the form of an external task. When a Service Task is declared external, the process engine offers a work item to workers that independently poll the engine for work to do. This decouples the implementation of tasks from the process engine and allows to cross system and technology boundaries. See the user guide on external tasks for details on the concept and the relevant API.
To declare a Service Task to be handled externally, the attribute camunda:type
can be set to external
and the attribute camunda:topic
specifies the external task’s topic. For example, the following XML snippet defines an external Service Task with topic ShipmentProcessing
:
<serviceTask id="anExternalServiceTask"
camunda:type="external"
camunda:topic="ShipmentProcessing" />
Camunda Extensions
Attributes
camunda:asyncBefore,
camunda:asyncAfter,
camunda:class,
camunda:delegateExpression,
camunda:exclusive,
camunda:expression,
camunda:jobPriority,
camunda:resultVariable,
camunda:topic,
camunda:type,
camunda:taskPriority
Extension Elements
camunda:errorEventDefinition,
camunda:failedJobRetryTimeCycle,
camunda:field,
camunda:connector,
camunda:inputOutput
Constraints
One of the attributes camunda:class
, camunda:delegateExpression
,
camunda:type
or camunda:expression
is mandatory
camunda.org and docs.camunda.org are part of Camunda Platform
Built by camunda and contributors — Privacy Statement — camunda Services GmbH © 2023
The content on this site is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.