Variable scope in an application

0
New to the platform and would like to load a variable in the main module and have the be in scope throughout the application without having to pass it as parameters. Searched documentation and community and haven't seen anything, so I am sure it's obvious and I am just missing it.
asked
4 answers
0

Brian,

If this is a value that may change per environment (i.e. different in dev, accp, production), you can use constant's for this (https://docs.mendix.com/refguide/constants).  These are set in the environment configuration and usable throughout the app but can't be changed by the runtime.  If you need something that can be changed by the runtime and accessible throughout the application, you could accomplish this with an attribute on an entity (you could add an entity associated to session and populate the value there when a user logs in associated to CurrentSession, you could create a specialization of Administration.Account to use for your users and add an attribute there, or have a standalone entity that gets retrieved by a microflow you call where needed). 

Hope that helps,

Mike

answered
0

Thanks Mike, but I am really just trying to create a runtime variable that can be loaded via microflow and have it scoped throughout the application.  Was trying to keep the session as Anonymous but have the use do some action that could store the results and be referenced in any form or microflow

answered
0

Welcome Brian!

One of the most common ways to handle this is to create an object in your data model (persistent or non-persistent), and associate it to the System.Session object. In any microflow, there's a Session object available called $currentSession. You can use a Retrieve activity over association to get any data you have associated to that Session object.

So, I imagine you'll save the results from your first REST call to a list of objects. When you create those objects in a microflow, associate them to $currentSession, and then you can retrieve them in later microflows as needed.

EDIT: Here's a sample project. Download this file and open it (make sure you have Mendix 7.17.2 installed):

Download Link

answered
0

answered