Scripting with DMN inside BPMN

By
  • Blog
  • >
  • Scripting with DMN inside BPMN
TOPICS

30 Day Free Trial

Bring together legacy systems, RPA bots, microservices and more with Camunda

Sign Up for Camunda Content

Get the latest on Camunda features, events, top trends, and more.

TRENDING CONTENT

In Camunda, you can use scripts at different places of a process. For example, inside a Script Task, as an execution/task listener, as a condition expression on a sequence flow or inside an input/output mapping. Usually, the scripts are written in JavaScript, Groovy or JUEL.

Using the FEEL extension, it is also possible to write scripts in FEEL (Friendly Enough Expression Language) which is a part of the DMN specification.

Why should I care about it?

Some highlights of FEEL are:

  • date and time calculations
  • useful list operations (e.g. filter, projection, all/at-least-one-test)
  • a lot of built-in functions
  • Camunda Spin integration

If you already use DMN then you are more or less familiar with FEEL. So you can use this knowledge to write scripts also in BPMN.

In general, it can be nice to have only one expression language for both: BPMN and DMN. This makes it easier to understand and modify the process and the involved decisions.

Example

Assuming that you have the following order process

Example process

and the data model

class Order {
  private String id;
  private Date date;
  private List<OrderItem> items = new ArrayList<OrderItem>();
}

class OrderItem {
  private String id;
  private double price;
  private String status;
  private boolean inStock;
}

when you can implement the script task, the conditions and the multi-instance expression using the following FEEL expressions:

  • Check if all items are available:
every item in order.items satisfies item.status = "available"
  • Calculate the total price:
sum(order.items.price) 
  • Select the items to fetch (as input parameter):
(order.items[not(isInStock)]).id
  • Check if the processing took more than 3 days:
now() - order.date > duration("P3D")

Note that the expressions works in both cases: if the variable order is a regular Java object (i.e. default serialization) and if it is a Camunda Spin JSON object. You don’t need to transform the variable or use Spin in the expressions itself.

How to use it?

*The installation instructions are outdated. They refer to Camunda Platform with version 7.9. Check out the related issue for recent information.

With the Camunda distribution

  • download the JAR from GitHub (feel-engine-plugin-1.5.0-complete.jar)
  • copy it to the lib folder of the Tomcat server
  • add the plugin to the process engine configuration (conf/bpm-platform.xml)
<process-engine>
    <plugins>
        <!-- ... -->    
        <plugin>
            <class>org.camunda.feel.CamundaFeelEnginePlugin</class>
        </plugin>
    </plugins> 
</process-engine>

With an embedded Camunda engine

  • add the extension as dependency to your project POM
<dependency>
  <groupId>org.camunda.bpm.extension.feel.scala</groupId>
  <artifactId>feel-engine-plugin</artifactId>
  <version>1.5.0</version>
</dependency>
  • register the plugin in your process engine configuration
<bean id="processEngineConfiguration" 
 class="org.camunda.bpm.engine.impl.cfg.StandaloneProcessEngineConfiguration">
    <property name="processEnginePlugins">
        <list>
           <!-- ... -->
           <bean class="org.camunda.feel.CamundaFeelEnginePlugin" />
        </list>
    </property>
</bean>

Additional Information

You can find more information about the FEEL engine, the integration in Camunda BPM and examples on GitHub and the Wiki.

Camunda Developer Community

Join Camunda’s global community of developers sharing code, advice, and meaningful experiences

Try All Features of Camunda

Related Content

We're streamlining Camunda product APIs, working towards a single REST API for many components, simplifying the learning curve and making installation easier.
Learn about our approach to migration from Camunda 7 to Camunda 8, and how we can help you achieve it as quickly and effectively as possible.
We've been working hard to reduce the job activation latency in Zeebe. Read on to take a peek under the hood at how we went about it and then verified success.