Hi, Readers.
Last week we briefly discussed how to set Allow HttpClient Requests for multiple extensions (selected extensions) at the same time. I was then asked if it was possible to have a custom extension automatically enable Allow HttpClient Requests after installation. So in this post I wanted to share this briefly.
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.

This setting is saved in table 2000000201 “NAV App Setting”.


So we just need to add an install codeunit to the customization. More details: Writing Extension Install Code

This will automatically enable Allow HttpClient Requests after installation.

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)
codeunit 50114 ExtensionHandler
{
Subtype = Install;
trigger OnInstallAppPerDatabase()
var
NAVAppSetting: Record "NAV App Setting";
Info: ModuleInfo;
begin
NavApp.GetCurrentModuleInfo(Info);
if NAVAppSetting.Get(Info.Id) then
if not NAVAppSetting."Allow HttpClient Requests" then begin
NAVAppSetting."Allow HttpClient Requests" := true;
NAVAppSetting.Modify();
end;
end;
}
END
Hope this will help.
Thanks for your reading.
ZHU
コメント