MENDIX Adding Validation Rules efficiently using rules

david medragh
3 min readApr 15, 2022

Let say we want to checks on a forms that the content of many fields is not empty

to manage this efficiently we will use A rule and add the validation on our save form button

First we will create a rule

Here the rule checks that the input is not empty only
Here the rule verify that the input param is not empty

what is a rule?

A rule is a special kind of microflow. Its result should be an enumeration or a Boolean and it can be used in a decision to make a decision based on that result. The idea is that complicated decisions can be consolidated in rules and reused in various places.

Rule Differences from Microflows

Rules are very similar to microflows
There are only a few differences between rules and microflows:
A rule can only be used in a decision
The return type has to be Boolean or enumeration
A rule cannot change data in the database
the actions to create, delete, change and rollback objects are not available in rules
A rule cannot interact with the client
the actions to show or close forms, show messages, send validation feedback and download files are not available in rules
A rule cannot call web services, generate documents or import XML

Lastly on your microflow where you will add your validation add the validation activities with the above created rule

For each Decision, select Rule in Decision Type, select the rule Rule_StringNotEmpty and set the argument to $Employee/Title, $Employee/Firstname and $Employee/Lastname respectively. Give each a descriptive caption, and then set the condition value for the red flows to true.

To ensure that the user is made aware of any problem in the form, you can use the Validation Feedback activity. This activity allows you to select an attribute on an entity so that Mendix can figure out where to show the validation message on the input form.

Add validation messages to the false flows of your decisions and set the variable, member, and Template properties accordingly.

The assistant here help us to add the validation feedback activity
here you can write the validation message you want to show to the end user

After each of the validation messages add a Change variable activity that sets the EmployeeValid variable to false. Finally, add Merge activities just after your Decision activities so that the microflow can continue processing.

--

--