How to Import a CSV | Mendix 10 (banner Image)
How to Import a CSV | Mendix 10

How to Import a CSV file| Mendix 10

--

In this blog I will cover the steps needed to successfully set up and import CSV Files into your Mendix App, using the CSV Module from the Marketplace.

Prerequisites Marketplace modules

Before starting the tutorial, ensure you have the Community Commons and the OQL modules installed in your project. If you don’t have it, you can install it using the following links.

Community Commons Module
OQL Module

Step by Step

1- After installing all the dependencies, download the CSV Module from the marketplace.

https://marketplace.mendix.com/link/component/108605

CSV Module — Marketplace

2- Currently the project has one entity called Request on the domain model. This entity has 3 attributes: Name, Status (Draft and Submitted), and RequestID.
Based on this domain model we create 2 pages: Overview and NewEdit

Request Entity
Request Entity Details
Request Entity — Generated pages

3- Create a new entity called CSVFile, it should be a generalization of System.FileDocument. There is no need to create attributes inside.

CSVFile — FilDeDocument Generalization
CSVFile Entity

4- Duplicate the Request entity, change the name to Request_CSV, and turn the option Persistable to NO. Modify the data type of the RequestID from auto number to Integer. This change is needed because a Non-Persistable entity can not have an auto number attribute.

Request_CSV Entity — NonPersistable
Request_CSV Entity

5- Go to the Request_Overview page and add a new button to the data grid. Write Import CSV as a caption and select Create Object as an On Click event.
Generate a new page called CSVFile_NewEdit and use it as the On Click page.

Import CSV Action button
Create new page — CSVFIle_NewEdit

6- Replace all fields inside the Dataview for a File Manager widget.

CSVFile_NewEdit Structure

7- Inside the File Manager, select Upload for the Type.

File Manager Widget Type

8- Double-click on the Save Button and change the On Click event to Call a microflow. Generate a new Microflow called ACT_Request_ImportCSV.

Save Button — Call Microflow

9- On the App Explorer, search for the CSV marketplace module and open the folder called USE_ME. Drag and Drop the Java action Import CSV to the microflow we just created.

ImportCSV Java action on Microflow

10- Double click on the java action and select the microflow parameter CSV file as an Input File. Copy all properties from the images below to your project.

Import CSV java action details
Import CSV java action details — Scroll down

11- Go to the App Explorer and open the folder Example inside the CSV module. Copy all the actions inside the CSV_ImportCSV.
Return to the java action, click to select a microflow, and generate a new one called ACT_Request_UploadCSV.
Paste all the actions to this microflow.

Import CSV Example microflow
Import CSV microflow input
Microflow to Upload CSV

12- Add a Create List action to the beginning of the microflow and select the Request entity. Change the name of the list to Request_toCommitList.

Add Request List to commit
Create a Request List to commit

13- Double click on the Read Next Line java action and select as an entity Request_CSV.

Change Entity on the Read Next Line Java action

14- Add a Create Object action to the false condition of the decision. Fill the attributes Name and Status with the $Line values.

Create a Request Object
Fill attributes values

15- Drag and drop the Change List action and add the object we just created to the Request_toCommitList.

Add a new object to the list

16- Go back to the ACT microflow and add 2 actions: Show Message and Close Page.

Add a Show message and close the page

17- Run the project

Run project

18- Create a CSV file to Import similar to the image below.

Example of a CSV file to import

19- Inside the app, click on the Import CSV button and select the file to import. Press the Save button and check if the data from the file is visible on the Overview page.

Import CSV button on the Request Overview page
Select a file to import
Request Overview after import

Join Me on Discord!

This is the end of the tutorial. Thank you for reading this far :)

I’m creating a Mendix community on Discord to make life easier for devs. You can ask questions, help other people, and have access to all the tutorials.
If you want to be part of this community, you can do so through this invite.

From the Publisher -

Inspired by this article to bring your ideas to life with Mendix? Sign up for a free account! You’ll get instant access to the Mendix Academy, where you can start building your skills.

For more articles like this one, visit our Medium page. And you can find a wealth of instructional videos on our community YouTube page.

Speaking of our community, join us in our Slack community channel. We’d love to hear your ideas and insights!

--

--

Mendix With Me
Mendix Community

Ricardo Pereira: Certified Mendix Expert from Portugal 🇵🇹 | Founder of Mendix With Me community | Join us on Discord: discord.gg/YHre8dXz3q