I am just starting developing an app in Mendix. I have created the domain model, and now I need to import some initial data, but all I've managed to find in the documentation is how to insert it manually.
Is there a way to do this?
I am just starting developing an app in Mendix. I have created the domain model, and now I need to import some initial data, but all I've managed to find in the documentation is how to insert it manually.
Is there a way to do this?
You can write a microflow to generate some initial data, and either a 'Scripts' page to run it manually, or have it run automatically on startup. In the latter case, you probably want to check for existing data first. Such a microflow could also (via custom Java logic) access the resources
folder and import data files from there.
There's also a feature App from a spreadsheet but you've probably already developed a part of the application already.
There is an approach to reading data that is referred to: "get or create", unlike a plain "get" operation.
In a nutshell, you substitute a get box that returns data of some type with a microflow-call box, that calls a microflow which performs the "get or create" action, and returns data of that type. This sub-microflow performs the following operations:
The "get or create" microflow, at minimum, has the following contents:
This approach can help in other situations too, like protecting you from non-initiated references to other ("parent") entities.
E.g. in a shipment tracking application: retrieving a shipment object without an owning depot could use "get or create" microflow in order to check for empty relations so that the application is protected against this unexpected situation, thus can react without an internal error.
Instead of creating a Microflow to generate your demo data, there is an alternative. This is especially beneficial when you want to add a lot of data to initialize your data.
You can create:
Click here for more information.