Dynamics 365 Business Central: Building a collection of recommended apps

Dynamics 365 Business Central

Hi, Readers.
About half a year ago, when we were discussing Business Central 2022 wave 2 (BC21) new features, we had discussed Easily find apps to connect to core services (easily discover and install third-party apps). Microsoft has added some recommended apps in certain BC versions. For example:

But in most versions, including the W1 version, there is nothing in the page.

So, in this post, I would like to talk about how to add your own recommended apps to Business Central.

Recommend Apps:
The Microsoft commercial marketplace offers a wide variety of apps from Microsoft and partners that extend the value of Business Central. As a Microsoft partner, you can save yourself, and your customers, a bit of legwork by using the Recommended Apps extension to curate a list of apps that are right for your customers’ businesses.

Recommended Apps is a per-tenant extension (PTE), which means that you can make collections unique for each customer, or build collections specifically for certain types of businesses or industries and then reuse the collections when you’re on-boarding those types of customers. For example, you can create one collection for customers who work in finance, and another for customers in the retail space.

You can only add apps that are available on AppSource to your collection. That is, you cannot host your own app and add it to the list.

Building collections requires some development. To make that easier, Business Central provides the following objects:

  • Recommended Apps List page
  • Recommended App Card page
  • Recommended Apps table
  • Recommend Apps codeunit

You must use the Recommend Apps codeunit to build collections. The following table provides an overview of the methods in the codeunit. You can copy the information for the parameters from the listing for the app on AppSource.

MethodDescription
InsertAppAdd information about the apps from AppSource to the Recommended Apps table. When adding new apps, you can simply paste the URL for the app from AppSource for the AppSourceUrl parameter, and Business Central will add the relevant parts to the other parameters. However, you must manually complete the Short DescriptionLong Description, and Recommended By parameters.
GetAppGet information from AppSource about the apps that are already added to the Recommended Apps table.
UpdateAppUpdate the information about the apps that are already added to the Recommended Apps table.
RefreshImageUpdate the logo for the app. When you insert an app, the image is downloaded automatically. Use if the logo has changed.
DeleteAppDelete an app from the collection. You provide the app ID.
DeleteAllAppsDelete all apps from the collection.
GetAppURLGet the URL for a specific app. You provide the app ID.

Let’s see more details.

First, since Recommended Apps are not included in the standard symbol files, you need to set the dependencies property separately and download it.

  "dependencies": [
    {
      "id": "a53a4bb0-aa53-8ff8-77d6-fe3388db0eb8",
      "name": "Recommended Apps",
      "publisher": "Microsoft",
      "version": "21.0.0.0"
    }
  ],

Execute the AL: Download symbols command.

codeunit 4750 “Recommended Apps”:

Well, first let’s test the InsertApp function and the DeleteApp function.

Test App: Spanish language (Mexico)

Test Video: Looks good.

Source Code:

pageextension 50115 RecommendedAppsListExt extends "Recommended Apps List"
{
    actions
    {
        addfirst(Processing)
        {
            action(AddRecommendedApps)
            {
                Caption = 'Add Recommended Apps';
                ApplicationArea = All;
                Promoted = true;
                PromotedIsBig = true;
                PromotedCategory = Process;
                Image = Add;

                trigger OnAction()
                var
                    RecommendedApps: Codeunit "Recommended Apps";
                    RecommendedBy: Enum "App Recommended By";
                begin
                    if RecommendedApps.InsertApp('334ef79e-547e-4631-8ba1-7a7f18e14de6', 0, 'Spanish language (Mexico)',
                    'Microsoft', 'This application adds the Spanish language (Mexico) to Microsoft Dynamics 365 Business Central', 'Dynamics 365 Business Central is available in many languages. By installing this application you add the capability of showing the base application in the Spanish language (Mexico)',
                     RecommendedBy::"Your Microsoft Reseller", 'https://appsource.microsoft.com/en-us/product/dynamics-365-business-central/PUBID.microsoftdynsmb%7CAID.spainmexicolangageforbc%7CPAPPID.9e737fc0-589a-436f-8b2f-0f27da2d2afd?exp=ubp8&tab=Overview') then
                        Message('Recommended App is added!!!');
                end;
            }
            action(DeleteRecommendedApps)
            {
                Caption = 'Delete Selected Recommended Apps';
                ApplicationArea = All;
                Promoted = true;
                PromotedIsBig = true;
                PromotedCategory = Process;
                Image = Delete;

                trigger OnAction()
                var
                    RecommendedApps: Codeunit "Recommended Apps";
                begin
                    CurrPage.SetSelectionFilter(Rec);
                    if RecommendedApps.DeleteApp(Rec.Id) then
                        Message('Recommended App is deleted!!!');
                end;
            }
        }
    }
}

Since this is hardcoded, I’d like to improve it and add an install button to the Card page.
PS: How to install AppSource extension/app via AL

Source Code: Github (Please note that the source code is for reference only, you can improve it according to your own needs)

pageextension 50115 RecommendedAppsListExt extends "Recommended Apps List"
{
    actions
    {
        addfirst(Processing)
        {
            action(AddRecommendedApps)
            {
                Caption = 'Add Recommended Apps';
                ApplicationArea = All;
                Promoted = true;
                PromotedIsBig = true;
                PromotedCategory = Process;
                Image = Add;

                trigger OnAction()
                var
                    AddRecommendedApp: Page "ZY Add Recommended App";
                begin
                    if AddRecommendedApp.RunModal() = Action::OK then
                        AddRecommendedApp.InsertRecommendedApp();
                end;
            }
            action(DeleteRecommendedApps)
            {
                Caption = 'Delete Selected Recommended Apps';
                ApplicationArea = All;
                Promoted = true;
                PromotedIsBig = true;
                PromotedCategory = Process;
                Image = Delete;

                trigger OnAction()
                var
                    RecommendedApps: Codeunit "Recommended Apps";
                begin
                    CurrPage.SetSelectionFilter(Rec);
                    if RecommendedApps.DeleteApp(Rec.Id) then
                        Message('Recommended App is deleted!!!');
                end;
            }
        }
    }
}

page 50116 "ZY Add Recommended App"
{
    Caption = 'Add Recommended App';
    PageType = StandardDialog;

    layout
    {
        area(Content)
        {
            field(AppId; AppId)
            {
                Caption = 'App Id';
                ApplicationArea = All;
            }
            field(SortingId; SortingId)
            {
                Caption = 'Sourting Id';
                ApplicationArea = All;
            }
            field(Name; Name)
            {
                Caption = 'Name';
                ApplicationArea = All;
            }
            field(Publisher; Publisher)
            {
                Caption = 'Publisher';
                ApplicationArea = All;
            }
            field(ShortDescription; ShortDescription)
            {
                Caption = 'Short Description';
                ApplicationArea = All;
            }
            field(LongDescription; LongDescription)
            {
                Caption = 'Long Description';
                ApplicationArea = All;
                MultiLine = true;
            }
            field(AppSourceURL; AppSourceURL)
            {
                Caption = 'AppSource URL';
                ApplicationArea = All;
            }
        }
    }

    var
        AppId: Guid;
        SortingId: Integer;
        Name: Text[250];
        Publisher: Text[250];
        ShortDescription: Text[250];
        LongDescription: Text[2480];
        AppSourceURL: Text;


    procedure InsertRecommendedApp()
    var
        RecommendedApps: Codeunit "Recommended Apps";
        RecommendedBy: Enum "App Recommended By";
    begin
        if RecommendedApps.InsertApp(AppId, SortingId, Name, Publisher, ShortDescription, LongDescription, RecommendedBy::"Your Microsoft Reseller", AppSourceURL) then
            Message('Recommended App is added!!!')
        else
            Error('Something is wrong!!!');
    end;
}

pageextension 50116 RecommendedAppCardExt extends "Recommended App Card"
{

    actions
    {
        addfirst(Processing)
        {
            action(InstallAppSourceExtension)
            {
                Caption = 'Install AppSource Extension';
                ApplicationArea = All;
                Image = Installments;

                trigger OnAction()
                var
                    ExtManagement: Codeunit "Extension Management";
                begin
                    ExtManagement.DeployExtension(Rec.Id, 1041, true);
                end;
            }
        }
    }
}

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

PS:
1. When you run the Recommended Apps extension, you need to allow requests to external services.

2. Please note the AppSourceURL parameter in the InsertApp function.

When it is empty, the error below is displayed.

A call to System.Text.RegularExpressions.Regex.Matches failed with this message: Start index cannot be less than 0 or greater than input length.Parameter name: startat

When it is not a valid AppSource URL, the error below is displayed.

Cannot add the recommended app with ID {334EF79E-547E-4631-8BA1-7A7F18E14DE6}. The URL 123.com is not formatted correctly. Are you sure that the information about the app is correct?

AppSource URL:

https://appsource.microsoft.com/en-us/product/dynamics-365-business-central/PUBID.microsoftdynsmb%7CAID.spainmexicolangageforbc%7CPAPPID.9e737fc0-589a-436f-8b2f-0f27da2d2afd?exp=ubp8&tab=Overview

And the GetAppURL function can only be called after it has been added to Recommended Apps.

As shown in the standard code, if you call before adding, the following error will appear.

3. table 4750 “Recommended Apps” is inaccessible due to its protection level.

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL