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.
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
LikeLiked by 1 person
That’s wonderful! Thanks a lot Stan.
LikeLike
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
LikeLike
Codeunit 457 has method GetApplicationFamily().
Is this always the 2 letters of the localization; W1, US, NL, IT, ….?
LikeLike