I want to declare a variable whose value can be displayed anywhere in app (on any page) and can be modified from any micro flow. how can we do that??
-
1You can create an entity to store the value of the variable and a microflow which will retrieve the data from that entity. You can customize the logic based on your need for eg. change the value or just simply retrieve and return. – Yatin Gaikwad Apr 22 '19 at 14:11
1 Answers
As all mutable values in mendix are represented by attributes in an entity, you need to create an entity in order to be able to modify a value. The closest thing to a global variable in Mendix is an attribute on a singleton entity.
Let's suppose we want to be able to change the some settings of your app through its UI or within a microflow. To do this we can create an 'AppSettings' entity with attributes for all the different "global variables" that need to be set.
To make it a singleton entity we need to make sure that there is only one object of its kind in the database. To do this it's a common practice to implement a 'GetOrCreate' microflow that retrieves the 'AppConfiguration' object from the database and creates one if there is none yet.
We can now use 'GetOrCreateAppConfiguration' anywhere, where we need to read or modify our app settings, such as a microflow.
Using'GetOrCreateAppConfiguration' we could also create and settings page, where admins can modify the AppConfiguration attributes using a DataView with a Microflow retrieve.
We can also use a dataview to display the AppName "global variable" to users and use conditional visibility based on feature flag "global variables" to show or hide UI elements. Note that this means that we should probably not to give regular users write access to 'AppConfiguration' attributes.

- 513
- 5
- 16
-
Thank you for you detailed answer. I am facing the issue when i change the value of this global variable through another micro-flow. It did not update the value in the page rather i need to refresh the page to see updated value why it is so?? even if I have checked radio button of Refresh in client to YES while committing this object – Al Fahad Apr 25 '19 at 12:22
-
Do tell me if you know how to fix that issue in which view did not refresh automatically when entity is updated. We manually need to reload it to see changes. – Al Fahad Apr 26 '19 at 11:40
-
Here is the question in which I have explained that problem. https://stackoverflow.com/questions/55868931/data-view-is-not-updating-when-entity-is-updated-in-mendix – Al Fahad Apr 26 '19 at 13:51