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.

2 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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s