- Microsoft Dynamics 365 Business Central Cookbook
- Michael Glue
- 385字
- 2021-06-24 13:24:15
How to do it...
- Open your AL project folder in Visual Studio Code.
- First, we need to extend the Application Area Setup table in the base application.
In Visual Studio Code's Explorer pane, right-click and create a new file named Application Area Setup Extension.al. In the Editor tab, add the following code:
tableextension 50101 "Application Area Setup Ext" extends "Application Area Setup"
{
fields
{
field(50100; "Television Shows"; Boolean)
{
}
}
}
- Now, we need to add the logic to allow the new application area to be enabled.
In Visual Studio Code's Explorer pane, right-click and create a new file named Enable TV Application Area.al. In the Editor tab, create an empty codeunit like so:
codeunit 50104 "Enable TV Application Area"
{
}
- We need to add a couple of subscribers to our codeunit so that the base application knows about our new application area and when it should be enabled:
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Application Area Mgmt.", 'OnGetEssentialExperienceAppAreas', '', false, false)]
local procedure OnGetEssentialExperienceAppAreas(var TempApplicationAreaSetup: Record "Application Area Setup" temporary)
begin
TempApplicationAreaSetup."Television Shows" := true;
end;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Application Area Mgmt.", 'OnValidateApplicationAreas', '', false, false)]
local procedure OnValidateApplicationAreas(ExperienceTierSetup: Record "Experience Tier Setup"; TempApplicationAreaSetup: Record "Application Area Setup" temporary)
var
InvalidErr: Label 'Television Shows should be part of Essential
in order for the application to work.';
begin
if ExperienceTierSetup.Essential then
if not TempApplicationAreaSetup."Television Shows" then
Error(InvalidErr);
end;
- Now, let's add two functions to the codeunit. One will allow us to enable the new application area, while the other will establish whether the new application area is already enabled:
procedure IsTelevisionShowsEnabled(): Boolean
var
AppAreaSetup: Record "Application Area Setup";
AppAreaMgmtFacade: Codeunit "Application Area Mgmt. Facade";
begin
if AppAreaMgmtFacade.GetApplicationAreaSetupRecFromCompany
(AppAreaSetup, CompanyName()) then
exit(AppAreaSetup."Television Shows");
end;
procedure EnableTelevisionShows()
var
AppAreaSetup: Record "Application Area Setup";
ExperienceTierSetup: Record "Experience Tier Setup";
AppAreaMgmtFacade: Codeunit "Application Area Mgmt. Facade";
begin
if ExperienceTierSetup.Get(CompanyName()) then;
if not ExperienceTierSetup.Essential then
exit;
if AppAreaMgmtFacade.GetApplicationAreaSetupRecFromCompany
(AppAreaSetup, CompanyName()) then begin
AppAreaSetup."Television Shows" := true;
AppAreaSetup.Modify();
AppAreaMgmtFacade.SetupApplicationArea();
end;
end;
- Now, let's publish our application to verify whether our new application area is available:
- Press F5 to build and publish your application.
- Once you log in to your sandbox, use the icon to go to the Application Area page and you will see the new Television Shows entry. It will be disabled, as shown here: