the world of model driven development

Archive for the ‘Mendix’ Category

6 Steps to Mastering the Basics of the Mendix Excel Importer

The ability that Mendix gives modellers to import excel files into their application is fantastic for a number of reasons – my favourite being that it gives the end user so much more flexibility when it comes to uploading data into the application you’re building.

Here’s how to get a simple excel file imported into your Mendix application using the Mendix Excel Importer Module available for free of the Mendix App Store.

Step 1: Getting Started

Before creating the project it’s important to select, as your language format, USA English or Dutch. The reason is that there is no other language standard to the excel importer so you’ll end up with loads of blank fields which you’ll have to populate yourself (you can, of course, implement your own labels based on the language you chose but to save time it’s best to start with either of those two). The excel importer works using the Reflection module. In order to proceed you’ll need to download both the reflection module as well as the excel importer module. If you download the excel importer first you’ll notice a large number of errors due to the missing reflection module which is automatically resolved upon installation of the reflection module.

Step 2: Fire up that Domain Model

The next step will be to, like all good designs, start with the domain and create a domain model that you’re going to upload the contents of the excel file into, in this case we’ll create a very simple person entity as well as the overview and newEdit file after which we will connect our navigation settings up with the required pages that will implement the excel import module as well as the reflection module — which is needed for synchronizing our objects, allowing the excel importer to access them. Here is a pic of both the domain model I used for the post and the excel file we’re going to upload later.

Example of the excel file and the domain model

4 Navigation points need to be established:

  1. ExcelImporter.Templates_Overview
  2. MxModelReflection.MxObjects_Overview
  3. ExcelImporter.Import_Overview
  4. Person_Overview

Step 3: Sync the Objects

Firstly you’ll need to sync your objects so that the excel importer can get ahold of it so start up the application and navigate to the MxObjects_Overview page and click on the “sync” button. If you run a search your search results should now be populated by your currently instantiated objects.

Synchronizing Objects

Step 4: Creating the Upload Template

There are 2 ways to create a template with this module. For this post we’re just going to show how to create one by importing an excel spreadsheet. Now navigate to your Template_Overview page and click on the “New From File”. When using a spreadsheet  the application will not be able to interpret xlsx files so you’ll have to be sure that the excel is an xls file. Upload the file and select the relevant sheet index, header row number and first data row number.

Step 5: Now Configure the Template

After you’d uploaded the template page you’ll need to set uploaded columns against the entity you’re planning on uploading the document into and clicked save the application will navigate you to the template page whereby you will be required to complete the template creation process. If you’re stuck with the default USA label, you will have to set the Mendix Object to the entity are uploading, in this case the person entity .

Next you’ll need to “map columns to attributes”. Assign each Column number to an attribute on our domain and only set the unique key to “Yes” on the email attribute. After all the attributes have been set save the template.

Step 6: Import the Data into the Application

Navigate to the Import Files page and create a new import.

Importing Data into the Application

Once the import file has been created simply select the uploaded file and click on the import microflow which will complete the import process. You can now navigate to the person overview page and search for the data which you have imported into the application.

Get Create – A solution to the dilemma of using Entities in quantum states.

A common problem I come across in developing Mendix applications is when I have to manipulate an entity in a microflow which may or may not exist. This quantum  occurance would occur when having to update an entity from a 1-1 relationship, or on a 1-* where the child entity (on the many relationship side of things) is also related to a secondary attribute, such as a day or version.

When dealing with this situation you have to try retrieve the entity using the relationship or Key Attribute(such as date), check if it exists, if it doesn’t  create the entity with the new Key Attributes. This now leaves us with two  entities which have to be manipulated seperately or reretrieve the entity into  a common name.

Going with the first case lets look at what my first pass solution would look like on the following Module:

As can be followed from the above microflow there will be much duplication of logic, and complication of the microflow at quick inspection.

Note: When checking to see whether an entity I retrieved exists I like to create an exclusive split with the caption ‘Exists?’ and the formula ‘not($Entity=empty)’. This keeps the reading of the flow in the positive light rather than negative.

The solution I follow now as my standard practice in these circumstances is to create a microflow called Entity_GetCreate which will handle this retrieve or create logic for me and return the respective entity so that I dont need to concern myself with handling these cases seperately.

This GetCreate microflow for the above entity would look as follows:

Which results in the original microflow being simplified to:

Much easier to read for business and mendix users.

Model Driven Development and Beyond!

Model driven development and beyond! See what I discover what works and what doesn’t.

I will be blogging on my Mendix development experiences and Modeling in general. The challenges that await the world of interdependence between business and IT. So, here we go.

Adventures await!

Design a site like this with WordPress.com
Get started