This how-to explains how you can add advanced logic to a microflow by configuring a merge and a change object activity in Mendix Studio.
A merge is used to combine flows into one. If you split the microflow flow (with a decision) and now one and the same action needs to be executed for these separated flows, you can combine the two (or more) flows using a merge. For more information on decision, see Decision.
This how-to will teach you how to do the following:
- Configure the merge in the microflow that contains a decision
- Configure the change object activity after the merge
This how-to describes the following use case:
In Configure a Decision Step 1: Build the Domain Model & Configure a Microflow you have configured the decision to open a specific page depending on the customer’s grade. In case the customer’s grade is not indicated, the error message is shown. So you have four flows after the decision:
- Showing a page for bronze grade customers
- Showing a page for silver grade customers
- Showing a page for gold grade customers
- Showing an error message if the customer’s grade is not filled out
In this how-to, you will merge flows for bronze, silver, and gold customer grades to set object (Customer) to active status when customers open their personal order form.
To start this tutorial, make sure you have completed the following prerequisites:
- Create the microflow with the decision: Configure a Decision Step 1: Build the Domain Model & Configure a Microflow
3 Creating a Merge
To create a merge for gold, silver, and bronze customer grades in a microflow, follow these steps:
Open the microflow named Show_grade_specific_page.
Open the Toolbox tab > the General section, drag and drop the Merge activity at the end event of the flow labelled Bronze.
To merge the flow labelled Gold with the Bronze one, do the following:
a. Delete the End event of the flow labelled Gold.
b. Hover over the Show Page activity.
c. Click one of the dots that will turn into an arrow.
d. Drag the arrow to the merge. Now the Show Page activity is connected to the merge.
Repeat step 3 for the flow labelled Silver.
As a result, you have three flows merged into one.
4 Configuring Change Object
Now you will add logic to the microflow. You have merged three flows into one to set customer’s status to active irrespectively of their grades. Setting the status of the customers to active can be used, for example, to identify who of the customers are using their account, and who are not.
Do the following:
First of all, you need to add a new attribute to Customer entity in the domain model to indicate if customer is active or not. Click the domain model icon in the left menu bar to open the domain model and do the following:
a. Click the Customer entity > New attribute.
b. In the Create New Attribute dialog window, set Name to Active and Type to Boolean.
c. Click Create.
Now you will configure a new activity in the microflow. Open the microflow named Show_grade_specific_page.
In the Toolbox > Object Activities select the Change Object activity, drag and drop it after the merge in the microflow.
In the Properties tab for the Change Object activity, do the following:
a. Set Variable to Customer because you are going to edit Customer.
b. Click Add New Value.
c. In the Change value dialog window, select the attribute named Active, then click the Expression tab, and type true. This means that after the order form is opened for a specific customer, the customer’s status is set to active (active=true), no matter what grade this customer has.
d. Click Add to finish setting the value for the Active attribute.
e. In the Properties tab > the Behavior section do the following: leave the Commit option set to Yes, (this means the object will not be changed further and your changes will be saved (committed) to the database).
Congratulations! Now you have the microflow that works the following way:
- Analyzes if the customer has a grade, and does one of the following:
a. If the customer has a grade, it opens the order form for the corresponding customer grade.
b. If the customer does not have a grade, the error message pops up.
- If the customer has the grade, the customer’s status is set to active irrespective of the grade once the order form is opened.
Now you can preview or publish your app. For more information, see Previewing & Publishing Your App.