Service Task

Service Task
A Service Task is a Task that uses some sort of service, which could be a Web service or an automated application.
— BPMN 2.0.2 Standard, 10.3.3, Service Task

In Flowable, Service Tasks are used to perform some form of "technical" task. Whenever you want to perform calculations, trigger some action within your application’s back end or integrate with another system, it often involves Service Tasks. Most custom tasks such as the Email task or the HTTP Task are specialized versions of Service Tasks. This is possible thanks to the extensible nature of the BPMN standard which allows us to create our own tasks based on an existing type. For more information on creating a custom service task see Implement a Custom Service Task.

It is possible to configure Service Tasks in four ways:

  • Use a Value Expression.

  • Specifying a class that implements JavaDelegate or ActivityBehavior.

  • Evaluating an expression that resolves to a delegation object.

  • Invoking a method expression.

In many cases you want to store the result of an operation carried out by a Service Task in a variable. The resulting variable name is specified in the Result variable attribute.

Example

The following example shows a very simple process where a user enters some information about a client. The following service task then takes that information and creates a new client in the company’s operational systems.

Service Task

Attributes

Group Attribute Description

General

ID

The unique identifier of the element within the process model.

Name

The name of the element. This is the name displayed in the diagram.

Documentation

A description and additional information about this element.

Details

Execution listeners

Active Execution Listeners of the activity. This lets you react to the following events:

  • Start: Occurs when the activity is started.

  • End: Occurs when the activity is completed.

Expression

An expression which is resolved once the task is executed. The expression can either be a value expression such as ${firstName} or it can resolve a named object (e.g., a Spring Bean) and interact with it. For instance, in the above example, a possible expression could be ${clientService.createNewClient(firstName, lastName, email)}.

Delegate expression

An expression which resolved to a named object (e.g., a Spring Bean) which either implements the class JavaDelegate or ActivityBehavior.

Result variable

The name of the variable in which the result of the Service Task’s execution is stored. If no result variable is indicated, the result is discarded.

Use local scope

Indicates whether to store the result variable as a local variable.

Class

The fully qualified name of a class which either implements the class JavaDelegate or ActivityBehavior.

Asynchronous

When enabled, the activity is started as an asynchronous job. The process state is persisted before this element is executed. Then the process execution is resumed asynchroneously. This can be used when the execution of an activity takes a long time to return the user interface. However, if an error occurs before the following wait state, there is no direct user feedback.

Class Fields

Class fields make it possible to inject field values into your delegated class. You can either inject a fixed string value or an expression. See the section 'Field Injection' of the Flowable documentation for more information.

Triggerable

Sets the Service Tasks to be triggerable. This makes it possible that an external trigger determines when to continue the execution of the process once the Service Task was executed. For instance, in the above example, such an external trigger could be the activation of the new client.

Skip expression

Defines an expression which is evaluated before executing the task. If it evaluates to true, the task is skipped.

Skip expressions are only be evaluated if there is a process variable _ACTIVITI_SKIP_EXPRESSION_ENABLED with the boolean value true.

Is for compensation

Determines whether the activity can serve as a compensation for another activity.

Multi instance

Multi instance type

Determines if multiple instances of this activity are created. There are three choices:

  • None (default, only one instance is created).

  • MI parallel (activities are created in parallel. This is a good practice for User Tasks).

  • MI sequential (activities are created sequentially. This is a good practice for Service Tasks).

Once a type other than None is chosen, the following options appear:

  • Collection: The number of instances is determined by the elements of a collection. For each element in the collection, a new instance is created.

  • Element variable: The variable under which each element is available to the newly created instance.

  • Element index variable: The variable under which the current number of iterations is stored.

  • Completion condition: An expression which, if it evaluated to true, stops the creation of new instances.

  • Cardinality: An expression or numeric value (integer) which determines how many instances are created.

Visual

Font weight

The font weight of the element in the diagram.

Font size

The font size of the element in the diagram.

Font color

The font color of the element in the diagram.

Font style

The font style of the element in the diagram.

Background color

The background color of the element in the diagram.

Border color

The border color of the element in the diagram.