This is the last how-to in a series of five on how to create a simple HRM app. In this how-to, you will learn how to smarten up your application by adding business logic.
This how-to will teach you how to do the following:
- Create a microflow
- Build business logic
Before you can start with this how-to, make sure you have completed the following prerequisite:
- Complete the fourth how-to in this series: Build a Simple HRM App Step 4: Enrich the GUI with Filter Options.
3 Creating a Microflow
In this section you will create a microflow.
3.1 Adding an Action Button That Calls a Microflow
To add an action button that calls a microflow, follow these steps:
- Open the Employee_Overview page of the MyFirstModule module.
Right-click the grid control bar of the data grid in the Master Detail container and select Add button > Action:
To learn more about action buttons, see Action Button in the Mendix Reference Guide.
Double-click the new button and change the caption of the button to Promote:
Select Call a microflow as the on click event:
To learn more about a microflow, see Microflows in the Mendix Reference Guide.
Click Select to select a microflow:
Click the MyFirstModule module, and then click New to add a new microflow to the Responsive module:
Enter Employee_Promote in the Name field, then click OK to create the microflow:
Right-click the new button and select Go to microflow:
The microflow should look like this:
3.2 Adding an Exclusive Split
To add an exclusive split, follow these steps:
Select an exclusive split from the toolbar of the microflow editor:
To learn more about exclusive splits, see Exclusive Split in the Mendix Reference Guide.
Click a point on the line to add the exclusive split to the flow:
Double-click the new exclusive split to open the properties editor:
Enter Level? in the Caption field.
Place your cursor in the Expression field and then press CTRL + SPACE to bring up a list of suggestions:
To learn more about microflow expressions, see Expressions in the Mendix Reference Guide.
Select $Employee (MyFirstModule.Employee) from the list of suggestions. This employee object corresponds to the input object of the microflow:
Add a forward slash (“/”) to the value in the Expression field. This will show all the attributes of the employee object:
Select Level (Enumeration ‘Level’):
Click OK. The exclusive split will now evaluate the values from the Level attribute:
Double-click a point on the line between the exclusive split and the end event, and then select Junior from the Value drop-down menu:
Click OK. When the employee in the input parameter has the Junior level, this path will be executed:
Select an end event from the toolbar of the microflow editor:
To learn more about an end event, see End Event in the Mendix Reference Guide.
Add an end event to the flow:
Drag a line from the exclusive split to the new end event:
Double-click a point on the line between the exclusive split and the new end event, and then select Medior in the Value drop-down menu:
Repeat steps 10–16 for the Senior and (empty) values. The microflow should look like this:
3.3 Adding Activities to the Microflow
To add activities to the microflow, follow these steps:
Drag a Change object activity from the Toolbox to the Junior path:
To learn more about activities, see Activities in the Mendix Reference Guide.
Double-click the new change object activity to open the Change Object properties editor:
Select Employee (MyFirstModule.Employee) from the input Variable drop-down menu:
Set Commit to Yes. This will save the change to the database.
Set Refresh in client to Yes. This will update the value in the UI.
Click New to add a new change item:
Select Level (Enumeration ‘Level’) from the Member drop-down menu:
Select Medior from the Constant drop-down menu, then click OK:
Click OK to save the change object properties. The microflow will look like this:
Repeat steps 1–10 for the Medior path. Make sure that you set the level value to Senior. The microflow should then look like this:
Drag a Show message activity from the Toolbox to the Senior path:
Double-click the show message activity to open the Show Message properties editor.
Enter Employee is already at senior level in the Template field, then click OK:
Drag a Change object activity from the Toolbox to the path that will be executed when the employee has no level.
Repeat steps 2 through 10 for this new change object activity and make sure that you set the level value to Junior. The microflow will look like this:
4 Viewing Your App
To view your app, follow these steps:
- Click Run, then Save and continue, and then View App.
- Click Employees in the navigation list, and then select an employee with the Medior level.
- Click PROMOTE. The level of the employee will change from Medior to Senior.
- Click PROMOTE. You will see a message that you cannot promote the employee because the employee is already Senior.
Great! You completed all of the how-to’s!
We are very interested in your feedback. Please take this short survey to let us know what you think about this how-to.
6 Related Content
- Build a Simple HRM App Step 1: Create, Manage, and Deploy the App
- Build a Simple HRM App Step 2: First Steps in Building a Rich GUI
- Build a Simple HRM App Step 3: Show Related Data in the GUI
- Build a Simple HRM App Step 4: Enrich the GUI with Filter Options
- Testing Microflows Using the UnitTesting Module