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:
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:
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):
If I call the GetPeriod function with 2 as input parameter (State = Paid) this is the return:
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.