Extracting and Using Sub-Microflows

Last modified: August 20, 2024

Introduction

When building microflows that span multiple functions, the best practice is to break down the large microflow into sub-microflows. Sub-microflows represent individual parts of the whole microflow, for example, specific functions.

You can reuse any sub-microflows in other parts in the application. Furthermore, when you have very large and complex microflows, using sub-microflows can help you better manage your logic and business processes. Use sub-microflows to make your microflow easier to understand, modify, and troubleshoot if needed.

For example, you can use sub-microflows to construct a microflow that imports data into the system. A data import process usually consists of several stages, such as data validation, data import, and mapping the data into your Mendix domain model. As a best practice, instead of creating a single large microflow, you should extract the validation and mapping stages into their own sub-microflows to better manage the logic.

This document teaches you how to do the following:

  • Create sub-microflows by extracting them from an existing microflow
  • Troubleshoot extractions of sub-microflows
  • Use existing microflows as sub-microflows

Creating Sub-Microflows

You can create a sub-microflow by extracting a part of an existing microflow. The following example microflow checks to see if a registration has a trainee assigned and a registration date. If the registration passes both checks, the registration is committed to the database.

An example of a complex microflow for validating an object and committing it to a database

In this scenario, it makes sense to create a sub-microflow for the validation steps. If you do this, you can reuse this sub-microflow in other microflows if you need to validate a registration again.

To extract the validation steps into a sub-microflow, follow these steps:

  1. Select the area that you want to capture and use as a sub-microflow.

    Selecting an area to use as a sub-microflow
  2. Right-click an item in the selection, and then select Extract submicroflow.

    Selecting the Extract submicroflow menu option
  3. In the Add microflow dialog box, enter a name for the sub-microflow.

  4. Click OK.

  5. Open the sub-microflow by right-clicking the sub-microflow call and selecting Go to microflow.

    Multiple actions replaced with a microflow action
  6. Make any other required configuration changes depending on the contents of the sub-microflow.

    For example, the sub-microflow shown in the image below does not return anything, so the sub-microflow call cannot be used in the Is Valid? check that immediately follows it.

    Sample sub-microflow for registration validation

    To stop or continue your microflow based on the sub-microflow’s outcome, right-click the Create Boolean Variable activity and select Set $isValid as return value.

Troubleshooting Sub-Microflow Creation

If you get errors while extracting a sub-microflow, follow these steps:

  1. Verify that you provided the right input and output parameters for the sub-microflow.
  2. Check if the parameters are correctly configured.
  3. Make sure that you highlighted the correct activities to turn into a sub-microflow.

Using Existing Microflows as Sub-Microflows

You can use an existing microflow as a sub-microflow. For example, after creating the validation sub-microflow, you can reuse it wherever you need to do a registration validation.

To reuse an existing microflow, follow these steps:

  1. In the App Explorer, find the microflow that you want to reuse as a sub-microflow.
  2. Drag it onto the working area of another microflow, as shown in the following:
Dragging a microflow onto the working area of another microflow

Read More