Dynamics 365 Business Central: How to set Allow HttpClient Requests for multiple extensions (selected extensions) at the same time

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about a question I saw this morning in the Business Central forums, how to set Allow HttpClient Requests for multiple extensions (selected extensions) at the same time.

As you might know, you can integrate Business Central apps/extensions with external systems by using the HttpClient data type in your AL code. So you may have seen the following dialog prompting.

The extension ‘System Application by Microsoft’ is making a request to an external service. Do you want to allow this request?

The call might fail in the Business Central platform before actually reaching the external web service. It’s therefore important that you check for this in your AL code. Common error examples are if you have added duplicate request or content HTTP headers, if there are networking/firewall issues, if the URI cannot be resolved with DNS, or if the app/extension has not been configured to allow HttpClient requests in the Extension Settings.

To enable outbound HTTP calls, go to the Extension Management page in Business Central, and choose View.

Then, on the Extension Settings page, make sure that Allow HttpClient Requests is selected. This setting must be enabled for each app/extension, including library apps. More details: Call external services with the HttpClient data type

Of course, if you select Allow Always in the dialog prompting, this option will be automatically enabled. But there is a small problem here. This option needs to be enabled manually in each environment, otherwise the user will see the dialog prompting of the initial sharing. If the user selects Block Always, it will not pop up again.

So is there a way to enable this setting in bulk? Yes, but it requires some simple customization. Let’s see more details.
This setting is saved in table 2000000201 “NAV App Setting”.

The scope of this table is Cloud and it is extensible.

But please note, Extension Management page cannot be extended, so we need to create a new page that displays all extensions.

The application object or method ‘Extension Management’ has scope ‘OnPrem’ and cannot be used for ‘Cloud’ development. AL AL0296

We can use table 2000000153 “NAV App Installed App”:

More details: How to list all installed extensions/apps in your Business Central environment (Including hidden apps – “_Exclude_……”)

For example,

PS: Table 2000000201 “NAV App Setting” is a system table and data cannot be imported through the Configuration Package.

Then add a action to enable Allow HttpClient Requests for the selected extensions.

In addition, to make it easier to confirm whether the settings have been updated, I added the View action, just like the standard.

Let’s look at a simple test.

Done.

Test video:

Very simple, give it a try!!!😁

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

page 50106 "Installed Apps"
{
    ApplicationArea = All;
    Caption = 'Installed Apps';
    PageType = List;
    SourceTable = "NAV App Installed App";
    UsageCategory = Lists;
    Editable = false;
    InsertAllowed = false;
    SourceTableView = sorting(Name)
                      order(ascending)
                      where(Name = filter(<> '_Exclude_*'));

    layout
    {
        area(Content)
        {
            repeater(General)
            {
                field(Name; Rec.Name)
                {
                    ToolTip = 'Specifies the name of the extension.';
                }
                field(Publisher; Rec.Publisher)
                {
                    ToolTip = 'Specifies the value of the Publisher field.', Comment = '%';
                }
                field(Version; VersionNo)
                {
                    ToolTip = 'Specifies the value of the Version field.', Comment = '%';
                }
                field("Published As"; Rec."Published As")
                {
                    ToolTip = 'Specifies the value of the Published As field.', Comment = '%';
                }
            }
        }
    }

    actions
    {
        area(Processing)
        {
            action(View)
            {
                Caption = 'View';
                Image = View;
                ShortcutKey = 'Return';
                ToolTip = 'View extension details.';
                Promoted = true;
                PromotedCategory = Process;
                RunObject = page "Extension Settings";
                RunPageLink = "App ID" = field("App ID");
                Scope = Repeater;
            }
            action(EnableAllowHttpClientRequests)
            {
                ApplicationArea = All;
                Caption = 'Enable Allow HttpClient Requests';
                Promoted = true;
                PromotedCategory = Process;
                Image = EnableAllBreakpoints;

                trigger OnAction()
                var
                    InstalledApp: Record "NAV App Installed App";
                    NAVAppSetting: Record "NAV App Setting";
                    i: Integer;
                begin
                    i := 0;
                    InstalledApp.Reset();
                    CurrPage.SetSelectionFilter(InstalledApp);
                    if InstalledApp.FindSet() then
                        repeat
                            if NAVAppSetting.Get(InstalledApp."App ID") then
                                if NAVAppSetting."Allow HttpClient Requests" = false then begin
                                    NAVAppSetting."Allow HttpClient Requests" := true;
                                    NAVAppSetting.Modify();
                                    i += 1;
                                end;
                        until InstalledApp.Next() = 0;
                    Message('Enabled Allow HttpClient Requests for %1 installed apps.', i);
                end;
            }
        }
    }

    var
        VersionNo: Text[30];

    trigger OnAfterGetRecord()
    begin
        VersionNo := Format(Rec."Version Major") + '.' + Format(Rec."Version Minor") + '.' + Format(Rec."Version Build") + '.' + Format(Rec."Version Revision");
    end;
}

PS:
1. Dynamics 365 Business Central: How to get all dependent packages (dependencies Setting) for the extension

2. How to list all installed extensions/apps in your Business Central environment (Including hidden apps – “_Exclude_……”)

END

Hope this will help.

Thanks for your reading.

ZHU

コメント

Copied title and URL