Dynamics 365 Business Central: how to detect if your extension is running on a Sandbox

During our Extension Development workshops for Dynamics 365 Business Central, some developers are start asking for scenarios where in my extension I need to detect if it’s running on a Sandbox environment or in a production one.

From an extension, you can detect if it’s running on a Sandbox environment by using the Tenant Management codeunit (417). This codeunit provides a set of useful functions for retrieving informations about the Dynamics 365 Business Central tenant and platform. Here is a quick sample:

IsSandbox_00

In order to retrieve if your extension is running on a sandbox or on a production tenant, you can call the IsSandbox or IsProduction methods respectively.

You can also retrieve informations about the tenant, like Tenant ID and Name, Platform version and Application version by calling the functions I’ve showed in the second message in my AL code.

When running this simple extension from Visual Studio Code, this is the output you obtain:

IsSandbox_02.jpg

and these are the tenant and platform informations (these are related to my sandbox version):

IsSandbox_03.jpg

There’s also a second way to retrieve if an extension is running on a sandbox and it’s by using the Permission Manager codeunit (9002) and its IsSandboxConfiguration method:

IsSandbox_01.jpg

This is only an alternative way because this second function calls the function defined in Tenant Management codeunit.

4 Comments

  1. I’m happy to say that we have simplified this process by adding helper functions in COD2300 for the Business Central Fall 2018 release:
    IsEvaluationMode
    IsTrialMode
    IsTrialSuspendedMode
    IsPaidMode
    IsPaidWarningMode
    IsPaidSuspendedMode

    Liked by 1 person

  2. Seems like the codeunit is now 457 “Environment Information”.
    Would be nice to get more background information about how the following DotNet variables used in 457 and 2300 work:

    TenantLicenseStatePeriodProvider: DotNet TenantLicenseStatePeriodProvider;
    TenantLicenseStateProvider: DotNet TenantLicenseStateProvider;

    The readme.md does not give that much extra information.
    https://github.com/microsoft/ALAppExtensions/tree/master/Modules/System/Environment%20Information

    Like

  3. Codeunit 457 has method GetApplicationFamily().
    Is this always the 2 letters of the localization; W1, US, NL, IT, ….?

    Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.