Multi Tenant 


How to assign a TenantID explicitly to an Application?

Hi Jovvy

I'm not sure if I am understanding your question, but it's not possible to assign a TenantId explicitly to an application because Tenants are created and disabled at runtime. When an end-user is logging on, the OutSystems Platform infers the tenant where user belongs, using the username, and then the end-user is bound to his tenant.
What you are able to do, is to expose TenantId for an entity, by checking the "Show Tenant Identifier" property, available in the Advanced tab of the Entity Editor.
For more information about multi-tenancy this is a good article: How to Build a Multi-tenant Application.


Hi Claudia,

Yes, we just realized that it was not possible to set an TenantID to an application in runtime. Instead we passed the TenantID in url query parameter and to make it work perfectly we have to exposed the TenantID for an entity and yes, By checking the "Show Tenant Identifier".





There is a way to change Tenant context at runtime: Use system action TenantSwitch( TenantId).

You should not expose the TenantID of entities, by checking the "Show Tenant Identifier" in the entity, unless you really need to, because you then lose the automatic selection that the OutSystems platform does when querying (aggregates or SQL) the database.


1) Yes, you can pass the TenantID,

2) But then you should change the Tenant context using TenantSwitch(),

3) And then query the database using normal queries, without the need of exposing the TenantID on the entities.


FYI, using TenantSwitch has some consequences:

* It can be a bit slow.

* It performs a CommitTransaction

In other words, it is fine to do it... say... during a login... but doing it in the general course of work just to get access to data is wrong. Much better to expose tenant IDs on entities and carefully handle them... best of all to only do that in select espaces where you do it for all entities and expect them to work across tenants.


As Justin said it is better to expose TenantIds but if you don't want create complications in your current application, create a new project as DataMT (example) where MT means Multi Tenant and then in this project add dependecies for your tables, now here you can expose TenantId and you can create public Actions that returns your data of all Tenants, this is useful for reports where you need to aggregate informations.