What are you looking for?

Scripting with DMN inside BPMN

  • Blog
  • >
  • Scripting with DMN inside BPMN

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

See how Openreach and BT Group took a phased approach to transforming a complex legacy system.
Wilson Gaitan, director of data governance at Sam's Club/Walmart, tells us how to unlock efficiency and compliance in the world of big data.
At CamundaCon 2024 Berlin, MetaOps discussed how they used data-driven insights to transform operational oversight for the UK General Register Office.