Goal: I have a module which contains a table. When I click on a row in the table I would like it to update a global app variable.
Details: I have create the global app variable "str_ACCOUNTID" however, when I click on the "OnSelectedRow" even of the table, and trap the "OnClick" even. I select "Set Variable" as the action, drop down the "State" text box, and my Global Variable isn't in the list, only local variables.
Could someone please explain to me how to access the Global Variables from a module, bit it via GUI options, or using "Run JavaScript" as the event action?
Am I going to have to use system-wide "Environment" Variables? Instead.
Thanks ScottR that was helpful, and exactly what I've been trying - but I'm not able to do the same as you. I can't refer to the app's global variables in my table event code - it doesn't seem to realise the variables exist. I think this is because my table is part of a re-usable "module", and the module is then placed in the app.
The module seems to be a shield between the table and the global variables; probably because you can use a module in any number of apps and therefore that's probably why it can't "see" any one particular app's global variables.
Does anyone know how to reference an app's global variables from a component within a module? Or, do I have to set the variables at environmental / company level instead?
This is not something I realised you could do! I'm impressed, I'll have a read, thank you. Hopefully I can post the variables "in" when the module is launched - however, it's firing the values back out and populating the app "globals" which worries me.
My other option is to have a session-based list of values that I store in the back-end DB, which I can then chop and change from any module in any app, but that gives me a DB overhead concern if there are 100s of users all flipping through records and screens.
I literally have a bunch of entities (customer, person, contract etc...) and I want to store a CONTRACT_ID, PERSON_ID, CUSTOMER_ID etc... each time a user clicks on an "action" - so then when page is changed or action is taken, all the "last selected" IDs are used. Does that make sense? I'd rather not do it via URL parameter passing.
I'm afraid solution didn't work for me as posting the variable values back out of the modules was too complicated for me to figure out.
I think I'm going to need to store the IDs in the DB back end, but this only works easily if the user has a single browser tab open. If the user has multiple browser tabs open they'll all be competing to place data against the same record unless I have some way of uniquely identifying each browser tab / session; again, something I really can't figure out. It seems like it should be a really simple thing to do but I can't find anything in the documentation or forums about identifying individual browser tabs.
Modules can never directly reference App variables, because modules are designed to be reusable across different Apps. However, as @ScottR noted, you can pass data to modules or return data from them for use in the parent App. Because a module doesn’t know that an App’s variables exist, it cannot directly update those variables.
However, you can pass queries to the module that can be triggered from within the module to update App variables. You can pass module data using additionalScope.
Why not “Environment” Variables?
Environment variables are global, but typically used for things like secrets or environment-specific settings. They’re not really designed for dynamic user data.
Module inputs do have the limitation of being scoped to the single tab, and they get reset when you reload a page Would localStorage be helpful for your use case?
Local storage would only help if there is a "cookie per browser tab" otherwise variables would be constantly overwriting themselves as the user hops from tab to tab and changes data for different customers. Is this the case do you know?
Otherwise, the only solution I can see is being given the ability to retrieve the server "SessionID" per tab. Has there been any progress in this request please? There was talk of exposing it to the code so that we could have a consistent reference ID that is available across modules. At the moment, modules cannot see app-global variables (as they can be used across apps) - so we need to be able to see a consistent ID across modules in an app so they can identify what instance / tab / session the modules is part of, and therefore pick up global variables from a backend DB instead, using the ID.