Global Variable in Mendix

0
Is it possible to have a global level variable in Mendix app ? I want this variable to be set on startup or through some microflow and modify it through some other microflow. This variable should be accessible throughout the application. 
asked
3 answers
3

You could create a settings Entity and per user create a Session entity. This way you can also do settings per user. The only thing you need to do, when someone logs in, is get or create this Session entity and make a reference to the user itself. That way you can also persist these settings throughout the app. I usually make Settings persistent, and Session a non-persistent one. If you then make a reference to the current user and session, it will be kept in memory while the user is logged in.

answered
2

You can always make some helper entity in your domain model. With this you can make the variable configurable on runtime and you can use it on any microflow/page where necessary. Just make sure only 1 of this helper object exists in your application by doing a GetorCreate (which you can also put in your After Startup microflow)

But it depends on what you’re trying to use this for. Can I ask you what your use case is?

answered
2

If you want to share values among multiple users, my best bet would be to create GlobalSettings entity.
You can create the entity if it does not exist yet at startup, using an after startup microflow and retrieve/update it using a regular microflow.
If you want it to be user specific, you could could also use an entity and link it to their user account using an association. As Larn indicates, you can then build a microflow which first tries retrieve the entity and if it does not exist creates a new entitity. (Also called a GetOrCreate microflow)

answered