Extend application areas

Completed

Application areas let you hide certain user interface elements (including page fields, actions, and report request page options) based on the application area to which they belong.

Application areas represent a feature in the system that offers developers, administrators, and users the ability to define different user experiences. Controls that define these items can be tagged with one or more application areas by setting the ApplicationArea property. This property is a text type that contains a comma-separated list of application area tags. An application area tag must have the Name format, where name is the application area. The name can be any combination of letters (Aa-Zz) and numbers (0-9) without spaces. For example, to specify the Basic and Fixed Assets application areas, set the property to Basic, FixedAssets.

If the control applies to all application areas, you can set the property to All. This setting means that the control will always appear in the user interface.

This property is used together with the ApplicationArea function to hide user interface elements.

ApplicationArea('MyArea');

When the ApplicationArea function is called in a client session, only those controls that are tagged with the application areas that are set by the function will appear in the user interface. If one or more application areas are enabled in a session, controls that are not tagged with an application area won't appear in the user interface.

You can extend the existing application areas with your own application area to enable more or fewer business scenarios.

To register a new application area, follow these steps:

  1. Add a new application area in the Application Area Setup table.

  2. Enable the application area in the OnInstallAppPerCompany trigger.

  3. Extend the experience tier in the OnGetExperienceAppArea event.

  4. Modify the experience tier (optional).

  5. Validate the application area in the OnValidateApplicationAreas trigger.

tableextension 50101 Customer extends Customer
{
    fields
    {
        // Add changes to table fields here
        field(50100; Facebook; Text[50])
        {
            DataClassification = CustomerContent;
            Caption = 'Facebook';
        }
    }
} 

pageextension 50100 CustomerListExt extends "Customer List"
{
    layout
    {
        addafter(Name)
        {
            field(Facebook; Facebook)
            {
                Caption = 'Facebook';
                ApplicationArea = SocialMedia;
            }
        }
    }

    trigger OnOpenPage()
    var
        EnableSocialExtension: Codeunit "Enable Social Media Extension";
    begin
        if EnableSocialExtension.IsSocialApplicationAreaEnabled() then
            Message('App published: Social Extension');
    end;
}

To add an application, you need to extend the Application Area Setup table. After you have extended the table, a new Boolean field will be added, and the name of this field will be used in the attribute that you want to be tagged with this application area. Spaces in field names are omitted in the ApplicationArea attribute.

tableextension 50100 "Social Area Setup" extends "Application Area Setup"
{
    fields
    {
        field(50100; "Social Media"; Boolean)
        {
        }
    }
}

The Install Social Media Extension codeunit is of the subtype Install, and it enables the application area inside the OnInstallAppPerCompany trigger.

codeunit 50101 "Install Social Media Extension"
{
    Subtype = Install;

    trigger OnInstallAppPerCompany()
    var
       EnableSocialExtension: Codeunit "Enable Social Media Extension";
    begin
       if(EnableSocialExtension.IsSocialApplicationAreaEnabled()) then
          exit;

       EnableSocialExtension.EnableSocialMediaExtension();

       // Add your code here
    end;
}

The registration of the application area inside an experience tier is made inside the OnGetEssentialExperienceAppAreas trigger. Different versions of this event exist, one for each experience tier and, in this case, Essential is selected. This selection will make the extension visible inside the Essential experience and the event exposes an Application Area Setup temporary record, TempApplicationAreaSetup, to the Application Area Setup table. At this point, to enable the application area, you need to set this option to true.

Another ability that you have inside these methods is to modify the experience tier. You can also modify other application areas, such as creating an extension that extends Fixed Assets functionality. By subscribing to OnValidateApplicationAreas, the application area inside an experience tier is validated. OnValidateApplicationAreas will be implemented after the events in the OnGetExperienceAppArea family. The validation is necessary in the presence of extensions that are concurrently manipulating the same application areas.

If a needed application area isn't enabled, the suggested action is to show an error and turn off the extension to avoid unintended behavior. However, if the functionality that is controlled by this application area is of secondary importance and its loss does not affect the rest of the extension, it is also appropriate to keep the extension enabled.

codeunit 50103 "Enable Social Media Extension"
{
    // Extend and modify Essential experience tier with "Social Media App Area"
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Application Area Mgmt.", 
                     'OnGetEssentialExperienceAppAreas', '', false, false)]
    local procedure RegisterSocialExtensionOnGetEssentialExperienceAppAreas
        (var TempApplicationAreaSetup: Record "Application Area Setup" temporary)
    begin
        TempApplicationAreaSetup."Social Media" := true;
        // Modify other application areas here
    end;

    // Validate that application areas needed for the extension are enabled
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Application Area Mgmt.", 
                     'OnValidateApplicationAreas', '', false, false)]
    local procedure VerifyApplicationAreasOnValidateApplicationAreas
        (ExperienceTierSetup: Record "Experience Tier Setup";
         TempApplicationAreaSetup: Record "Application Area Setup" temporary)
    begin
        if ExperienceTierSetup.Essential then
            if not TempApplicationAreaSetup."Social Media" then
                Error('Social Media App Area should be part of Essential in order 
                       for the Social Media Extension to work.');
    end;

    procedure IsSocialApplicationAreaEnabled(): Boolean
    var
        ApplicationAreaSetup: Record "Application Area Setup";
        ApplicationAreaMgmtFacade: Codeunit "Application Area Mgmt. Facade";
    begin
        if (ApplicationAreaMgmtFacade.GetApplicationAreaSetupRecFromCompany(
            ApplicationAreaSetup, CompanyName())) then
            exit(ApplicationAreaSetup."Social Media");
    end;

    procedure EnableSocialMediaExtension()
    var
        ApplicationAreaMgmtFacade: Codeunit "Application Area Mgmt. Facade";
    begin
        ApplicationAreaMgmtFacade.RefreshExperienceTierCurrentCompany();
    end;
}