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:


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:


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


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:


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

Comment List