SwitchTenant in mobile app

SwitchTenant in mobile app

  

I'm trying to automatically switch tenant depending on the location of the device.

I'm doing it in the OnInitialize event (client action) of the app default screen:

- Get the location from Location Plugin

- If successful, call a custom server action that switches tenant (with TenantSwitch)

- Back to OnInitialize create/update local storage table

The TenantSwitch changes tenant as expected but after getting back to OnInitialize the tenant is set back to Users (default tenant).

What am I doing wrong? Is it from being set in a server action? If so, is there a similar client action?

Hello, did you set the app`s 'Is Multi-tenant' option?

Maybe this link can give you some help: https://success.outsystems.com/Support/Enterprise_Customers/Maintenance_and_Operations/How_to_Build_a_Multi-tenant_Application

Joao Melo wrote:

I'm trying to automatically switch tenant depending on the location of the device.

I'm doing it in the OnInitialize event (client action) of the app default screen:

- Get the location from Location Plugin

- If successful, call a custom server action that switches tenant (with TenantSwitch)

- Back to OnInitialize create/update local storage table

The TenantSwitch changes tenant as expected but after getting back to OnInitialize the tenant is set back to Users (default tenant).

What am I doing wrong? Is it from being set in a server action? If so, is there a similar client action?

Hi Melo,

Switch tenant server action set tenant id at server side. 

Did you using local storage table in your applications?


Thanks,

Rajat



@Mauricio

Yes, the app is set to multi-tenant.


@Rajat

Yes, I do use local storage in this mobile app.


Hi João,

The User_Login server action provided by the Users application is used by default to login users, as you can see if you open the DoLogin server action on your mobile application.

If I remember correctly, the implementation of this action will switch to the tenant the user belongs to. If you want to switch tenants, you probably have to do it after login (or make sure the user that logs in is from the right tenant).

You may also check previous post on the same general topic, might give you some ideas: https://www.outsystems.com/forums/discussion/32720/multiple-mobile-app/


@Jorge

The thing is I have a custom translation engine based on database multi-tenant tables. In order to show the appropriate translated text I have to previously switch to the right tenant, even before the login, just according to the device location (Location Plugin).

I have a similar process in the web application and it's working fine.

Joao Melo wrote:

@Mauricio

Yes, the app is set to multi-tenant.


@Rajat

Yes, I do use local storage in this mobile app.


Hi Joao,

Tell me one thing if you are using local storage table to store data then where you are facing problem. According to me what you can you that at the time of login you can keep tenant id from server table to one local table. Now you can store all the data in local when finally you push data to server just push all local data to server action where you have one input parameter tenant id or you can use switch tenant action at that time and implement data insertion code in server action.


Thanks,

Rajat Agrawal




Solution

I ended up with a slightly different approach.

When initializing the app I query the device location and store the tenant to be used, depending on the location coordinates.

Later when logging in I force that the user is logged in the previously saved tenant (if the user doesn't exist in that tenant an error message is presented)

And that does it.

Solution