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

Join the Camunda Developer Newsletter

Get the latest events, release notes, and product updates straight to your mailbox

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 Platform

Related Content

What are business processes, and why are they important? Learn how they work, types of business processes, & why well-orchestrated processes are critical.
Study demonstrates significant benefits to adopting Camunda and provides a powerful customizable tool to help you understand the impact it can have on your organization.
Learn how Samantha, as a developer and a new Camunda user, explored Camunda Optimize to enhance their development process.