Dynamics 365 Business Central: How to find out whether an extension is running on On-premises or SaaS (Codeunit 457 “Environment Information”)

Dynamics 365 Business Central

Hi, Readers.
Today, I want to share another mini tip of Business Central, how to find out whether an extension is running on On-premise or SaaS. And will briefly introduce Codeunit 457 “Environment Information”.

When you customize extensions for Dynamics 365 Business Central, could you have some scenarios where you want to execute some codes only in a SaaS environment or in an On-premises environment?

You can easily do it in AL.

Please look at the Codeunit 457 “Environment Information”.
This Codeunit is saved in System Application.Source.

You can find IsSaaS() and IsSaaSInfrastructure() in this Codeuint.
IsSaaS(): Checks if the deployment type is SaaS (Software as a Service).
Note: This function will return true in a Docker container.

IsSaaSInfrastructure():Checks if the deployment infrastucture is SaaS (Software as a Service). 
Note: This function will return false in a Docker container.

For Example:

On SaaS:

On On-premises:

This is easy, right?

OK, with this Codeunit, You can also do the following things.

1. Checks if environment type of tenant is Production.

2. Gets the name of the environment.

For Example:

3. Checks if environment type of tenant is Sandbox.

4. Checks the deployment type is OnPremises.

5. Checks the application family is Financials.

6. Gets the application family.

For example:

7. Gets the version which a given app was installed in.

For Example: Base Application

Note: In BC14 and previous versions, the above Codeunit cannot be used. So you need to use Codeunit “Permission Manager”;


Hope this will help.

Thanks for reading.