Dynamics 365 Business Central: How to make extension only install on lower version of BC

Dynamics 365 Business Central

Hello everyone.
Today I want to share a question that a partner asked me last week. How to deliberately develop an extension that can only be installed on BC16, but not on the latest BC17. In other words how to make extension only install on lower version.

As we all know, there is a parameter in the app.json file to determine the minimum installation version called “runtime“.
The version of the runtime that the project is targeting. The project can be published to the server with an earlier or the same runtime version.

What to do now is the opposite of this. But why, maybe they want to test cases where major update failed or set some restrictions for the On-Promise version. It doesn’t matter, let us think about how we can do it.

The first thing that comes to mind is breaking changes. Yes, you can set an extension installation restriction based on the breaking change list, but that is not universal, so it is not recommended.

On Breaking Changes of Business Central 2019 release wave 2, There is such a record.
Breaking Changes

So let us pay attention to the following Codeunits.
codeunit 417 “Tenant Information”
codeunit 457 “Environment Information”

I created very simple extension to see what values they can output.

Version: W1 16.5 (Platform 16.0.15884.17819 + Application 16.5.15897.16082)Azure AD tenant: d8f36038-1f93-4543-affc-5dc92b6ee871, Environment: Sandbox (Sandbox)

Version: W1 17.0 (Platform 17.0.17020.17774 + Application 17.0.16993.0)Azure AD tenant: 7585b220-27a1-45e9-9ea6-8f738a28327e, Environment: Sandbox (Sandbox)

From the above example, we can find that it can be achieved by using the version of Base Application.

For example:
Write a very simple control in install codeunit.

When this extension is uploaded and installed.
Version W1 16.5: Completed

Version W1 17.0: Failed.

Could not install the extension ‘TestExtension’ by ‘YUN ZHU’ (version ‘1.0.0.1’) on tenant ‘msasia4477t57088561’ due to the following error: ‘You can not install this extension after Ver. 16’ and AL stack trace: ZYInstall(CodeUnit 50100).OnInstallAppPerCompany line 6 – TestExtension by YUN ZHU
“”Extension Triggers””(CodeUnit 2000000010).OnInstallAppPerCompany line 2

Following the above approach, we achieved our goal quite simply.

PS:
You can also use codeunit 9015 “Application System Constants” to get the version number
For example:

Note:
But please note that when the environment is upgraded, the install codeunit will not be run. So if you want your extension to fail during the upgrade, please increase your version number and use the upgrade codeunit, then upload extension from Extension Management and deploy to next major version.

Increase the version number.

Add upgrade codeunit, then package it.

Choose Upload Extension on Extension Management page.

Upload new extension and deploy it to next major version.

Deployed.

Environment updating…

Failed to update.

END

Hope this will help.

Thanks.

ZHU

コメント

タイトルとURLをコピーしました