Hi.
This topic seems identical to the question "Passing client variables between modules" however, the condition "with different user providers" changes everything.
Imagine I have a client variable named ValueX created in ModuleA running in UserProviderM, its value is saved in the browser under Local storage, with Key named $OS_UserProviderM$ModuleA$ClientVars$ValueX.
In ModuleA, I create a public client function name GetValueX, that just returns the value of Client.ValueX.
I now have ModuleB running in UserProviderN, who needs to get the value of above client variable.
In debug mode, the browser Developer Tools shows me the correct value saved in $OS_UserProviderM$ModuleA$ClientVars$ValueX. However, the result of calling the public client function GetValueX from ModuleA always returns empty.If I change the user provider of ModuleB to UserProviderM, I get the expected value.
It seems that the client action is running under the context of the user provider of ModuleB, meaning it is trying to get the value from Key $OS_UserProviderN$ModuleA$ClientVars$ValueX?
How can I get the value of client variable ValueX of ModuleA from ModuleB running in a different UserProvider? Note that I cannot set the variable from ModuleB, it needs to be created by ModuleA.
Create Client action in ModuleB which will return $OS_UserProviderN$ModuleA$ClientVars$ValueX value and use it in ModuleA
As noted, I need the client variable to be created in ModuleA and read by ModuleB.
My Apologies, I didn't get the question first, now I see. That's a big question! I think you can manually set local item localStorage.setItem('Provider_ValueX', ValueX) whenever client variable changes and then update it and then in consumer module use js as well to get it. It is not very likable as in both modules you are writing a hard code to set and get value but I think it should work. If you don't want this ValueX to be used in different modules accidentally or cause any security problems, you can also use encryption while saving it
In Module B, you can read the value from Module A using JavaScript like this:
localStorage.getItem('$OS_UserProviderM$ModuleA$ClientVars$ValueX');
However, the downside of this approach is that it involves hardcoding the variable name, which can lead to maintainability issues - especially if the variable name or module name changes in the future.
Thx, Nino and Mayank.
As I only need to get the value, I've changed the client action in ModuleA to get the value via JavaScript from the hardcoded localstorage item $OS_UserProviderM$ModuleA$ClientVars$ValueX, as you suggested.
The variable and module names will not change.
Hopefully Outsystems will not change the format of how the client variables are saved...
You are the most welcome. If you have doubt about variables format to be changed you can have a workaround with creating/ updating another item in local storage when assigning value of client variable, this way changed format won’t affect your code
The solution
works if both applications run under the same domain.
However, if ModuleA runs under domain DomainE.com and ModuleB runs under domain DomainF.org, how can ModuleB access the client variable set in ModuleA?
If domain is defferent then use Shared Storage via Server
When ModuleA sets ValueX, also persist it server-side (DB, cache, session, Redis, etc.)
ModuleB fetches it from the server.
This bypasses the client isolation completely.
Best option if you control both apps and need reliabilit
Hi. I've replied on the other thread
https://www.outsystems.com/forums/discussion/104003/pass-a-client-variable-between-modules-running-in-different-domains/