Blog Posts BPMN DMN

Custom logic in BPMN

Blog: Drools & jBPM Blog

There are several ways to add additional custom logic to the Business Process. This article provides a review of different possibilities and their pros and cons.

Embedded Code

The easiest way, but not the most comfortable, is to use Script Task and its Script field.

When you work with a Script Task, all you need to do is add the node to the process, and you are ready to write Java/JavaScript/MVEL code using the Script property of the task:

NOTE: JavaScript is deprecated and can be removed in the following releases

This way of adding custom logic to the process is very fast. Also, there are no performance issues since all scripts are processed just once with Java code and other assets during the project compile phase. However, this way is not very convenient in the long term due to hard maintainability.

Why use Script fields

Downsides of Script fields

NOTE: for jBPM there is also an additional option to write quick snippets of code with the same benefits and downsides as for Script fields: On Entry and On Exit Actions for different types of activities. This functionality is not present today in Kogito but it will be available very soon

Custom Task

Custom Tasks is a powerful feature. You can predefine the node’s different visual and runtime properties on the canvas. An example can be predefined input and output parameters, as well as a custom task icon, task name, documentation, and other task parameters. Also, using Custom Task, you can specify the custom LifeCycle of the task, which can be used to create a unique experience for the new BPMN node. Custom Tasks explained in detail in another article before. Below are the pros and cons of this type of activity:

Why use Custom Task

Downsides of Custom Task

Service Task

Service Task is a compromise between simplicity of Script Task and features of Custom Task and usually suitable for most of the use cases. Service task usage doesn’t need additional knowledge about implementation for Business Analysts, no need for additional files. Also not tied to any interface and don’t need any registration as Custom tasks do.

NOTE: In jBPM, Service Tasks can’t be placed inside of normal Java application life cycle which means it is not possible to use features like Java Annotations or CDI in Service Task if the project will run in jBPM. That’s why Custom Tasks can be preferable for jBPM projects. However, if the project will run under Kogito all features from the Java life cycle are available and Service Task can be a preferable choice.

How to use Service Task on Kogito

To use the Service task, you will need a Java bean located in your project or project dependencies and mark it with CDI annotation.

package com.github.hasys;

import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class TestService {

    public String greetUser(String name, Integer age) {
        System.out.println(String.format("Hello %s with age %o", name, age));

        return String.format("User %s greeted.", name);
    }
}

To configure Service Task to use this Java bean, its FQN should be used as Interface property and method name as Operation.

Assignments are used to send data to and get data from the Service Task. The output will always have the name Result for jBPM and can be any for Kogito. Inputs should be the same as the method’s parameters for both jBPM and Kogito:

You can check examples in detail in our kogito-examples repository.

Why use Service Task

Downsides of Service Task

Conclusion

There are several possibilities for how to add custom logic to your Process. All of them have their benefits and limitations to fill needs for any use cases.

The post Custom logic in BPMN appeared first on KIE Community.

Leave a Comment

Get the BPI Web Feed

Using the HTML code below, you can display this Business Process Incubator page content with the current filter and sorting inside your web site for FREE.

Copy/Paste this code in your website html code:

<iframe src="https://www.businessprocessincubator.com/content/custom-logic-in-bpmn/?feed=html" frameborder="0" scrolling="auto" width="100%" height="700">

Customizing your BPI Web Feed

You can click on the Get the BPI Web Feed link on any of our page to create the best possible feed for your site. Here are a few tips to customize your BPI Web Feed.

Customizing the Content Filter
On any page, you can add filter criteria using the MORE FILTERS interface:

Customizing the Content Filter

Customizing the Content Sorting
Clicking on the sorting options will also change the way your BPI Web Feed will be ordered on your site:

Get the BPI Web Feed

Some integration examples

BPMN.org

XPDL.org

×