Creating a Custom Save Button with a Microflow
Introduction
Mendix uses visual models called microflows to define the logic of your application. A microflow is a visual way of expressing what traditionally would be written in code.
This document explains how you can create a custom Save button on a detail page using a microflow. You need to replace the default Save button with a Save button that shows a custom message to end-users after they click it.
Before you continue, make sure you have completed the following:
-
Create a Customer entity with the attribute Name in your domain model (for more information, see Configuring a Domain Model).
-
Create a Customer_Detail page for the Customer entity (for more information, see Create overview and detail pages).
Replacing the Default Save Button with a Custom One
The detail page you just created has a default Save button. To recreate the behavior of this default button, you need to replace it with a custom one. To do so, follow these steps:
-
Open the Customer_Detail page.
-
Right-click the Save button and select Delete to remove it.
-
Open the Toolbox and search for Call microflow button there.
-
Drag the Call microflow button into the drop-zone under the Cancel button.
-
In the Select Microflow dialog box, click New to create a new microflow.
-
Set the Name as Customer_Save.
-
After the button is created, open its Properties pane.
-
In the General section, set the Caption as Save, and choose a floppy disk as the Icon:
You have created a button that calls a microflow.
Recreating the Default Save Behavior
The button you just created calls a microflow that does not do anything yet. To recreate the default Save behavior for this button, do the following:
-
Right-click the new Save button and select Go to on click microflow to open the new microflow. An example of how the microflow should like is below:
-
Open the Toolbox and search for the Commit object(s) activity there.
-
Drag the Commit object(s) activity into the flow between the start and end events.
-
Double-click the Commit object(s) activity to open its properties.
-
In the Input section, select Customer for Object or List.
-
Set Refresh in client to Yes and click OK:
-
Open the Toolbox, and find the Close page activity there.
-
Drag the Close page activity into the flow after the Commit object(s) activity:
You have recreated the default Save button logic.
Extending the Microflow with a Custom Message
To extend the logic with a custom message that is shown to end-users when they click the button, do the following:
-
Open Toolbox, find the Show message activity, and drag it after the Close page activity.
-
Double-click the Show message activity to open its properties.
-
In the Template column, type Customer is saved!.
-
Click OK to save the changes.
Congratulations! You have customized the Save button using a microflow:
Read More
- Microflows
- Advanced Validation with a Custom Save Button
- Using Validation Assist to Build Data Validations