The new way to call Mendix microflows from Java actions

Robert Price
Mar 3, 2020 · 3 min read

Mendix 8.7 has just been released, and with it comes a new way to call microflows in Java actions.

A new set of fluent Java actions have been added to replace the old execute method in the Core. We now use microflowCall to call a microflow, along with associated inTransaction, withParam, withParams, and execute methods. These form part of the new MicroflowCallBuilder interface.

Let’s have a look at a couple of practical examples.

First, we need to build a microflow for our Java Action to call. In this case, the microflow will accept two parameters, a String called Name, and an Integer/Long called MessageCount. There is a single activity in the microflow that just says “Hello Name, you have MessageCount messages.”. Name and MessageCount are substituted in from the microflow parameters. We’ll save it SUB_ShowMessageCount.

Our first Java action will use the withParam option when calling the microflow. First, we create the Java action. When we “Deploy for Eclipse” this creates a stub Java action for us to populate. In this case, we want to tell Donald he has 1234 messages.

// BEGIN USER CODE

If we call this Java action we call the SUB_ShowMessageCount microflow in the TestCallingJava module. We say we want it in a transaction, we also pass the Name and MessageCount parameters and values, then finally execute it in the current context. This will give us the following message.

Donald sees this message.

If we don’t want to use multiple withParam methods, we can build up a Java Map of key values and pass this using the withParams method. To call the same example, but to tell Boris he has 3 messages, we can use the following Java code.

// BEGIN USER CODE

This looks very similar to our previous example, but at the start, we build a HashMap of key values to pass in using withParams. Running this we get the following message on the screen.

Boris sees this message.

In summary

I hope this has given a useful overview on calling a Mendix microflow from a Java action. The changes Mendix have made here feel easier and clearer, which should lead to better code maintainability. Now… Go Make It!

Mendix Community

The community-sourced publication for low-code

Mendix Community

The community-sourced publication for low-code

Robert Price

Written by

With over 20 years of industry experience, Rob is primarily focused on delivering low code solutions using the Mendix platform. Find him at robertprice.co.uk

Mendix Community

The community-sourced publication for low-code