Dynamics 365 Business Central: How to install AppSource extension/app via AL

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about how to install AppSource extension via AL.
About two years ago, in How to install AppSource Extension in Dynamics 365 Business Central SaaS, we discussed that we have to use the Direct URL method to install AppSource extension when the app is set to Contact Me.

To install AppSource Extension do following: In address bar, append following to the base business central URL, then replace part with the AppSource Extension’s App Id.
?aid= FIN&page=2503&filter=%27ID%27%20IS%20%27<App ID>%27&signInRedirected=1

And in Install AppSource Apps via Admin Center API, we discussed how to install the AppSource Extension using the Admin Center API.

This time we discuss the third way, using AL code to install AppSource Extension.

There are two methods.

PS: As with the Direct URL or Admin Center API methods, you need to have the AppSource Extension’s App Id first. the following test uses the Shopify Connector.
Shopify Connector: ec255f57-31d0-4ca2-b751-f2fa7c745abb

1. Using System.Hyperlink Method

This method is similar to the Direct URL method, we can trigger the Extension Installation wizard by opening a hyperlink: https://businesscentral.dynamics.com?noSignUpCheck=1&filter=%27ID%27%20IS%20%27[AppID]%27&page=2503

For example,

We see that you have both a production and sandbox environment available. Select the environment to which you want the application installed.

Test Video:

Source Code:

pageextension 50100 CustomerListExt extends "Customer List"
{
    actions
    {
        addfirst(Category_Process)
        {
            actionref(InstallAppSourceExt_Prmoted; InstallAppSourceExtension)
            {
            }
        }
        addafter(ApplyTemplate)
        {
            action(InstallAppSourceExtension)
            {
                Caption = 'Install AppSource Extension';
                ApplicationArea = All;
                Image = Installments;

                trigger OnAction()
                begin
                    Hyperlink('https://businesscentral.dynamics.com?noSignUpCheck=1&filter=%27ID%27%20IS%20%27ec255f57-31d0-4ca2-b751-f2fa7c745abb%27&page=2503');
                end;
            }
        }
    }
}

2. Using codeunit 2504 “Extension Management”

Provides features for installing and uninstalling, downloading and uploading, configuring and publishing extensions and their dependencies.

We can use procedure DeployExtension(AppId: Guid; lcid: Integer; IsUIEnabled: Boolean)

AppId: The AppId of the extension.
lcid: The Locale Identifier. More details: Windows Language ID and Global Language ID
IsUIEnabled: Indicates whether the install operation is invoked through the UI.

For example,

Test Video:

Source Code:

pageextension 50100 CustomerListExt extends "Customer List"
{
    actions
    {
        addfirst(Category_Process)
        {
            actionref(InstallAppSourceExt_Prmoted; InstallAppSourceExtension)
            {
            }
        }
        addafter(ApplyTemplate)
        {
            action(InstallAppSourceExtension)
            {
                Caption = 'Install AppSource Extension';
                ApplicationArea = All;
                Image = Installments;

                trigger OnAction()
                var
                    ExtManagement: Codeunit "Extension Management";
                begin
                    ExtManagement.DeployExtension('ec255f57-31d0-4ca2-b751-f2fa7c745abb', 1041, true);
                end;
            }
        }
    }
}

Very easy, isn’t it?😁

Of course, you can also set the App ID and Language ID as variables, so you can install the AppSource Extension by asking the user to enter the App ID on the page.

Test Video:

Source Code:

pageextension 50100 CustomerListExt extends "Customer List"
{
    actions
    {
        addfirst(Category_Process)
        {
            actionref(InstallAppSourceExt_Prmoted; InstallAppSourceExtension)
            {
            }
        }
        addafter(ApplyTemplate)
        {
            action(InstallAppSourceExtension)
            {
                Caption = 'Install AppSource Extension';
                ApplicationArea = All;
                Image = Installments;

                trigger OnAction()
                var
                    AppSourceAPPDialog: Page "AppSource App ID Dialog";
                begin
                    if AppSourceAPPDialog.RunModal() = Action::OK then
                        AppSourceAPPDialog.InstallAppSourceExt();
                end;
            }
        }
    }
}

page 50100 "AppSource App ID Dialog"
{
    PageType = StandardDialog;
    Caption = 'AppSource App ID';
    layout
    {
        area(content)
        {
            field(AppID; AppID)
            {
                ApplicationArea = All;
                Caption = 'AppSource App ID';
            }
            field(LanguageID; LanguageID)
            {
                ApplicationArea = All;
                Caption = 'Language ID';
                TableRelation = "Windows Language"."Language ID";
            }
        }
    }
    var
        AppID: Guid;
        LanguageID: Integer;

    procedure InstallAppSourceExt()
    var
        ExtManagement: Codeunit "Extension Management";
    begin
        ExtManagement.DeployExtension(AppID, LanguageID, true);
    end;
}

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL