Camunda Team Blog

Hello ${name}! - Templating with camunda BPM

Written by Sebastian Menski on , under Execution category.
As part of our scripting improvements we also addressed templating as a new feature of camunda BPM. With the new camunda BPM 7.2.0-alpha3 release it is now also possible to use FreeMarker or Apache Velocity templates inside your BPMN process.


We integrated this template engines as JSR 223 compatible scripting engines. Therefore we create small wrappers for these template engines in our camunda-template-engines-jsr223 project. This has the advantage that we do not need new extension elements or attributes for the BPMN xml. Instead a template can be used everywhere a script can be used. This is especially useful for script tasks and input output mappings. If the template engine JSR 223 wrapper is part of your classpath you can use the name of the template engine as script language.

The maven coordinates of the template engine wrappers a the following if you want to use them with an embedded engine or in a JUnit test case:

<dependency>
  <groupId>org.camunda.template-engines</groupId>
  <artifactId>camunda-template-engines-freemarker</artifactId>
  <version>1.0.0</version>
</dependency>

<dependency>
  <groupId>org.camunda.template-engines</groupId>
  <artifactId>camunda-template-engines-velocity</artifactId>
  <version>1.0.0</version>
</dependency>


The following example shows a simple use case where an input output mapping is used on a service task to generate a text content needed by this task. Here we use the FreeMarker template engine to generate the body of an email.

As you can see the process variables in the current scope can directly be used in the template. The result of the processed template is than save in a local variable which is available inside of the service task.

Another interesting use case for templates are camunda connectors (added in 7.2.0-alpha2). As templates like scripts can be loaded from external resources it is possible to use the a SOAP envelope template in multiple processes or projects. An example for such an template can be found in our SOAP connector example.

As a side effect of this new feature we have demonstrated that you can now easily integrate own scripting-like languages in camunda BPM. If it is possible to create a JSR 223 compatible wrapper it can be used in camunda BPM.

To read more technical details about templating please visit our user guide. And please let us know what you think about this new feature.