Become a Rapid Developer
Module 7
Automating Processes within an App
2
7. Automating Processes within
an App
7.1 Automating Processes
You might have experienced that filling out long forms can be quite a tiresome process. Manually entering
names, addresses, postcodes, and dates can take some time, and therefore make the experience of the user
less pleasant.
As a Mendix Developer, you always want to keep your users’ needs a top priority. Microflows are your number
one tool in the quest to make the user’s journey as pleasant as possible. They allow you to build custom
functionality based on the specific needs of your users.
Do most of your users use the app on their phone while travelling? Do they need to fill out the same
information multiple times? Can some information be filled in automatically based on data that you already
have? These are all questions you need to ask yourself when thinking of how you can make your app more
effective.
If the answer to one or more of these questions is yes, then Mendix has a solution for you! By using microflows
you can automatically fill in data in the app. For example, in the LearnNow app, when you know the start date
of a training event and the duration of the course, you can automatically fill out the end date of the training
event. You can also automatically calculate the total number of registrations, or pre-fill certain fields when you
create something new from a certain page. That will definitely save Jimmy some time and allow him to focus
on improving his business.
In this module you will learn how to use Mendix Studio Pro to make your app more efficient by adding custom
logic using microflows. In detail, you will learn how to:
• Set up a widget event to trigger a microflow
• Create a microflow to change objects and values
• Solve errors to ensure your microflows work as intended
• Give indications to the users on what information they still need to fill out
Go ahead to the next lecture to learn how to automatically calculate the end date of a training event!
7.2 Automatically Fill out End Date
Currently, when Jimmy wants to schedule a training event, he has to fill out all the details manually. However,
he could save time and keep his data consistent by having the end date calculated automatically, based on the
start date of the training event and the duration of the course. This will save Jimmy some work, but it also
eliminates the chance of Jimmy accidentally selecting the wrong end date!
3
In the image below, you can see that, when Jimmy selects a Course and Start Date for a Training Event he is
about to create, the End Date is automatically calculated. Note that European date format is used in the
images of this course.
Let's formulate a plan for building this functionality. You will need a couple of steps:
1. The first step is to make sure the microflow is triggered. As the start date or the course type determines
the end date, a trigger should be set there. You can create this trigger by using a widget event. You
will need to add a widget event to the start date input widget and the course selector. The widget event
will trigger a microflow that calculates the end date. Obviously, you will need to create the microflow
itself as well.
2. The second step is to fill out the calculated end date. For this you will need to change the
TrainingEvent (Change Object activity) and set the new EndDate value. You are going to use
a microflow expression for this, the addDays function to be specific. This function adds a number of
days (the duration of the course) to a date (the start date).
3. After that, you deploy the app and test the functionality by entering data in the detail page in every way
possible and see if you can cause errors.
4. Next step is to learn how to analyze any errors that may have occurred, and adjust the microflow to
prevent these errors from happening again.
5. Finally, you will commit your work.
All these steps will be explained in more detail as you go through the assignments in this module.
4
7.3 Triggering a Microflow from an Input Widget
So, let's start with the first step: make sure the microflow is triggered when the user changes the course or the
start date of a training event.
As mentioned in the previous lecture, input widgets are typically used to show data to the user and allow them
to edit data. Some examples of input widgets are check box, date picker, radio buttons, drop down, and text
box. As you can see in the image below, the Course can be selected in the Training Event detail page using a
drop down. Also, the Start Date of the training event is selected using a date picker.
In the same way that buttons can trigger events when the user clicks on them (for example open a page, or call
a microflow), input widgets can do the same! The difference with input widgets is that the events can be
triggered at three different points:
• On enter: when the user enters (clicks on) the input widget
• On change: when the user leaves the input widget after making a change
• On leave: when the user leaves (closes) the input widget (no matter whether they changed the value of
the widget or not)
When using an input widget, one of the events you can select on enter, change, or leave, is “Call a microflow”.
You can use microflows to immediately check the value of a field and give immediate feedback to the end user.
You can also use input widgets to calculate values based on input changes and give this back to the end user
immediately.
5
For example, the input widget that changes the StartDate value can trigger a microflow:
• On enter: Then the microflow will be triggered once the user clicks on the agenda icon
• On change: Then the microflow will be triggered once the user changes the start date of the training
event. That could also mean that they change the value of the StartDate from “no selection” to a
specific date.
• On leave: Then the microflow will be triggered once the user opens the date picker and then closes it
again, no matter whether the changed the date or not.
Can you guess when you want to trigger the microflow that you will use to calculate the end date of the training
event automatically? Go to the next lecture to see how you can do it!
7.3.1 Set up the Input Widgets
In this assignment you will see how you can call a microflow from an input widget to fill out the end date of a
training event automatically. The microflow will calculate the following: EndDate = StartDate + Duration.
The StartDate is selected in the date picker input widget, and the Duration depends on the Course that is
selected in the drop down input widget. Therefore, as the user can change both the course and the start
date, you will need to set up both those input widgets to trigger the microflow! Let’s start with the first one.
Start Date Input Widget (Date Picker)
1. In Mendix Studio Pro, open the TrainingEvent_NewEdit page. You can double-click on elements in
Mendix Studio Pro to adjust their properties, just like using the Properties pane in Mendix Studio.
2. Double-click on the start date input widget to open its properties. A pop-up window opens. This window
allows you to control the settings of the input widget. There are four tabs in this window: General,
Common, Events, and Appearance. Open the Events tab. In this case you want to calculate the end
date when the start date has changed, so you need an On change event.
3. Set the On change event to Call a microflow. A selection window opens which allows you to select
one of the existing microflows or create a new one. The microflow to calculate the end date doesn't
exist yet. Click New to create a new microflow.
4. Remember the naming convention for microflows? Prefix_Entity_Operation. The prefix for an On
Change event is OCH. Give the microflow a clear name, according to the naming convention. This way
it will be easier for another developer to interpret what it is and what it does, should the need arise. A
good name is: OCH_TrainingEvent_CalculateEndDate.
评论3
最新资源