Dynamics 365 Business Central: how to check if your Extension is running on a trial tenant

An interesting question in an insider talk some days ago was how to check from AL code if my extension is running on a trial tenant or in a licensed tenant (paid).

After a bit of searching inside our lovely C/SIDE, I’ve found the solution to the question: in Dynamics 365 Business Central there are two useful objects useful for that scope:

  • Table Tenant License State (2000000189)
  • Codeunit Tenant License State (2300)

The License State table contains details of your tenant license such as Start Date and End Date and the State of your license (that is an option field with the following values: Evaluation,Trial,Paid,Warning,Suspended,Deleted,,,,LockedOut ).

To test if this works (and how it works), I’ve written a small function in AL:

CheckD365BCLicense_00.jpg

If you call the GetPeriod method of the Tenant License State codeunit by passing the option value for the state that you need to check, you have as return the remaining days for that state. This function returns -1 if your tenant license is not in the state you have as input.

For example, this is what I have if I run this code in a trial Dynamics 365 Business Central Tenant by calling the GetPeriod method with 1 as parameter (State = Trial):

CheckD365BCLicense_01.jpg

If I call the GetPeriod function with 2 as input parameter (State = Paid) this is the return:

CheckD365BCLicense_02.jpg

This could be a quick and easy mode to test if your extension is running in a trial tenant.

P.S. I suggest to Microsoft folks to add in the Tenant License State codeunit also other methods to retrieve for example the start and ending date of a license (or a state) without making a query on the Tenant License State table.

4 Comments

  1. Thanks for your feedback. New helper methods in Tenant License State codeunit will be available in the upcoming Dynamics 365 Business Central release in autumn 2018.

    Liked by 1 person

  2. Pretty insightful.. I’m wondering what is a possible use-case for this codeunit to be used in BC customizations probably in some apps which rely on licenses such as LS Central?

    Like

  3. Pretty nice article. I’m wondering what would the use case for this to be included in BC Customizations. Something like apps that rely on BC Licensing such as LS Central??

    Like

  4. Yes this test is useful on many AppSource apps. You release the app as a trial and on some cases you need to test if it’s running on a trial tenant or on a production one and enable/disable functionalities accordingly.

    Like

Leave a comment

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