10 tips for everyday Mendix development

Praharaj Mahaprasad Tripathy
Mendix Community
8 min readJun 20, 2022

--

10 tips for everyday Mendix development

The last few years of my journey with Mendix have been a beautiful story, about which I can speak forever. While Mendix academy, forum, docs, and colleagues played a crucial role in nurturing my Mendix knowledge, there are a few tips and tricks, both big and small, which significantly help in my everyday application development using Mendix.

Tip #1 — Mendix Studio Pro Layout

As a Mendix developer, most days we make use of the powerful debugging tools provided by Mendix out of the box. Have you wondered how many times you have had to switch between the Variables and the Debugger pane? Well, not anymore.

You can set up your Mendix Layout as per the following screen which helps you to keep a watch on your Variables and performs Debugging activities like Step into, Step over, Step out and Continue at the same time. Great hack when you spend most of your time debugging a Microflow/Nanoflow.

Pro-tip: you can also snap the Console directly in between the Variables and Debugger panes, so you can take advantage of log messages while debugging.

Tip #2 — Nanoflows to the Rescue

Ever wondered how to reduce the wait time for the user while saving/canceling changes and closing the page?

Imagine a user story where the user is present on a pop-up page. The below activities should be performed as part of the Save button

  1. Validate the changes
  2. If valid, send an email to the user
  3. Close the pop-up page to show the overview page again

The usual way of achieving this is to create a microflow on the click action of the Save button with the following activities:

Does the user need to wait for the “Send Email” activity to get completed before the pop-up page gets closed? If your answer to this is No, then converting this microflow to a nanoflow and bringing the “Close Page” activity before the “Send Email” activity helps reduce the wait time for the user.

The reason being is that when a nanoflow steps through its actions, client actions are executed directly. Therefore, the pop-up page will be closed before the “Send Email” activity starts.

Tip#3 — Debugging the After Startup Microflow

Ever faced the nightmare where your Mendix app failed to start? If Yes, pretty much you would have utilized the debugging tools and immediately placed a breakpoint in the After Startup microflow to debug it.

But wait, something went wrong, isn’t it? The breakpoint was never triggered! This is because of the Mendix design where the debugger is available only when the runtime has fully started.

If debugging the After Startup microflow is required, then remove the After Startup microflow from the configurations and call it from a temporary button on the app administrators homepage

Tip#4 — Changing an empty object

It wouldn’t be a surprise to state “Every Mendix developer, at least once, would have encountered the below error”

com.mendix.modules.microflowengine.MicroflowException: Change object ‘Some(Entity)’ should not be null

At times, even when we would have evaluated all the possible scenarios where a retrieved object cannot be empty, there might arise a corner case where a Change Object activity receives an empty object. This throws an error to the user.

It is always best to place an empty object check before changing the object to avoid the error.

Tip#5 — Empty string validation check

We write the following expression in a decision to check if a string attribute is empty or not.

$Entity/StringAttribute != empty

While this works for most of the time, there is a scenario where it doesn’t return the appropriate response. Consider the following situation -

a) A user creates a new object and hits on save button without filling the attribute value. Since the default value of a string attribute is empty, the empty check validation holds good.

b) A user edits an existing object, removes the value of the string attribute, and hits on save button without filling the attribute value. This time, the attribute value is set as ‘’ and not as empty. Hence our validation returns the incorrect result.

To ensure the validation logic works all the time, the best practice for an empty string check is to combine it with the trim function

trim($Entity/StringAttribute) != ‘’

Tip#6 — Moving entities from one module to another

Is your domain model overcrowded with a large number of entities? Time to segregate your domain model and move them into a newly created module to help in easier maintainability and modulization of your code. But how do we move entities across modules seamlessly?

Many of us would tend to achieve this by simply cutting (Ctrl + X) the entity in Module 1 and Paste (Ctrl + V) the entity in module 2. This results in the entity table being completely dropped and recreated as a new one, which in turn results in all the existing entity data getting wiped off from the database. That’s scary to even imagine, right?

Mendix provides an easy solution to this. Right-click on an entity in the domain model and click on “Move to” and then select the module to which it should be moved. The table gets renamed in the database with the new module name.

Tip#7 — Making use of Distraction Free Mode

Studio Pro layout gives us immense power and capabilities through the App Explorer on the left, Properties and Toolbox on the right, and Console, Change, and Debugger panes on the bottom of the screen leaving the remaining center area for us to design that beautiful page, microflows and whatever else.

Many times, there arises a situation where you have to debug a very complicated microflow or you need some additional area to view your snippet properly. This is exactly the time when we make use of the awesome Distraction Free Mode to hide all other panes except the main area.

It can be toggled by navigating to View > Distraction Free Mode

Shortcut Key for Distraction Free Mode — Shift + F11

Tip#8 — Using Enumeration instead of direct value comparison

An Enumeration attribute type is a great way to handle a list of predefined values.

Consider the below scenario where an Enumeration attribute called Stage has 3 values namely Stage1, Stage2, and Stage3. There are two ways to form the decisions of the microflows based on the stages as shown below

Method 2 has the following advantages over Method 1:

a) Execution time is faster since the decision is checked for only once.

b) When a new enumeration value is added (say Stage4), Mendix will automatically prompt you to go to the microflow and update what the flow should be for the new value.

Tip#9 — Deciding on the length of a string attribute

A string attribute often comes with an additional configuration to define the length of the string which can be either set to a Limited number of characters or it can be Unlimited.

Developers tend to limit the length of the string as much as possible since a smaller string length attribute has many advantages with few, such as -

a) Not all databases support indexes on strings of unlimited length.

b) Searching through a string attribute is faster when the string length is smaller.

However, there are moments when it is not quite easy to predict the maximum length of the field. In such cases, if the incoming data (like from Rest Service Import Mapping) has more characters than the string attribute can hold, it throws an error.

Tip#10 — Caution before cleaning up your App Explorer

There are days when we plan to clean up our App Explorer and delete those year-old excluded items, rename a few microflows/nano flows/pages, and exclude unused logic. To ensure that your cleanup activity doesn’t result in additional errors, you can refer to the below points -

a) When excluding a document, appending the Date of exclusion to the document name helps in differentiating between recent and old excluded items.

b) Microflows/Nanoflows called from JavaScript snippets or Deeplinks will not appear on Find usages. So, proper annotations should be provided to prevent other developers from accidentally deleting or renaming the document.

Conclusion

The root cause of a major issue can sometimes be a gap in knowledge about “the little things” while developing an app. While the list of Mendix tips is non-exhaustive, there are many other hacks that you might have already been implementing and the world is unaware of. What are you waiting for? Go ahead and share your tips and tricks with the world and remember “GO MAKE IT”.

Read more

From the Publisher -

If you enjoyed this article you can find more like it on our Medium page. For great videos and live sessions, you can go to MxLive or our community Youtube page.

For the makers looking to get started, you can sign up for a free account, and get instant access to learning with our Academy.

Interested in getting more involved with our community? Join us in our Slack community channel.

--

--