Dynamics 365 Business Central: How to check whether a specific extension is installed in AL

Dynamics 365 Business Central

Hi, Readers.
About a year ago, we discussed how to detect whether a specific extension is installed in AL. At that time we used NavApp.GetModuleInfo(Guid, var ModuleInfo) Method.

NavApp.GetModuleInfo(Guid, var ModuleInfo) Method: Gets information about the specified AL application.

That is also a very simple method. But while investigating how to install AppSource extension/app via AL recently, I found another easy way, just using codeunit 2504 “Extension Management”

Standard Source Code:

    /// <summary>
    /// Checks whether an extension is installed, based on its PackageId.
    /// </summary>
    /// <param name="PackageId">The ID of the extension package.</param>
    /// <returns>The result of checking whether an extension is installed.</returns>
    procedure IsInstalledByPackageId(PackageId: Guid): Boolean
    begin
        exit(ExtensionInstallationImpl.IsInstalledByPackageId(PackageId));
    end;

    /// <summary>
    /// Checks whether an extension is installed, based on its AppId.
    /// </summary>
    /// <param name="AppId">The AppId of the extension.</param>
    /// <returns>The result of checking whether an extension is installed.</returns>
    procedure IsInstalledByAppId(AppId: Guid): Boolean
    begin
        exit(ExtensionInstallationImpl.IsInstalledByAppId(AppId));
    end;

We need to use the Package ID or App ID of the extension.

For example, Shopify Connector
Package ID: fea2cfdf-9e03-4093-8847-483aee8348df
App ID: ec255f57-31d0-4ca2-b751-f2fa7c745abb

PS: An extension ID (App ID) is a 32-digit GUID, this is generally fixed and will not change, such as 72CC5E27-BD97-4271-AF55-F77E4471E493. More details: App Identity

But, please note that the Package ID is different, each time an extension is installed or upgraded, a new Package ID of the extension will be changed.

For example, I installed my extension twice.

And Shopify Connector extension in different environments.

Let’s go on. We can use the above method to check whether a specific extension is installed very briefly.

Source Code:

pageextension 50111 CustomerListExt extends "Customer List"
{
    trigger OnOpenPage()
    var
        ExtManagement: Codeunit "Extension Management";
        InstalledMsg: Label 'The Extension is installed, and the extension name is %1.';
        NotInstalledMsg: Label 'The Extension is not installed.';
    begin
        if ExtManagement.IsInstalledByAppId('ec255f57-31d0-4ca2-b751-f2fa7c745abb') then
            Message(InstalledMsg, ExtManagement.GetAppName('ec255f57-31d0-4ca2-b751-f2fa7c745abb'))
        else
            Message(NotInstalledMsg);

        if ExtManagement.IsInstalledByPackageId('fea2cfdf-9e03-4093-8847-483aee8348df') then
            Message(InstalledMsg, ExtManagement.GetAppName('ec255f57-31d0-4ca2-b751-f2fa7c745abb'))
        else
            Message(NotInstalledMsg);
    end;
}

Very simple, isn’t it? Give it a try!!!😁

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL