Exercise: Build an extension-safe work area

Completed

In this exercise, you assemble the review work area in a live Business Central online sandbox. Every artifact is supplied, so your task is to create the named files, preserve the IDs, publish the app, and verify the contract.

Prepare the AL project

Use Visual Studio Code with the AL Language extension and access to a Business Central online sandbox. Create an empty folder named WorkAreaExtension, then create the folders src, src/controladdin, and .vscode.

The baseline targets Business Central 2026 release wave 1 (version 28) with AL runtime 17.0. If AL: Download Symbols reports a newer required application, platform, or runtime, update only application, platform, and runtime in app.json to the values supported by the current sandbox. Keep the architecture, object IDs, and field IDs unchanged.

Create app.json:

{
  "id": "4f614f40-13cb-4bbd-b52e-24d005648b60",
  "name": "Extension Safe Work Area",
  "publisher": "Microsoft Learning",
  "version": "1.0.0.0",
  "brief": "A self-contained work area exercise.",
  "description": "Demonstrates compatible tables, pages, enums, a Role Center, and a control add-in.",
  "privacyStatement": "https://go.microsoft.com/fwlink/?LinkId=724009",
  "EULA": "https://go.microsoft.com/fwlink/?linkid=2009120",
  "help": "https://learn.microsoft.com/dynamics365/business-central/",
  "url": "https://learn.microsoft.com/dynamics365/business-central/",
  "logo": "",
  "dependencies": [],
  "screenshots": [],
  "platform": "28.0.0.0",
  "application": "28.0.0.0",
  "idRanges": [{ "from": 70300, "to": 70329 }],
  "runtime": "17.0",
  "features": ["NoImplicitWith"]
}

Create .vscode/launch.json. Replace the two environment values with the sandbox environment name and tenant ID shown in the Business Central admin center.

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "al",
      "request": "launch",
      "name": "Business Central sandbox",
      "environmentType": "Sandbox",
      "environmentName": "Sandbox",
      "tenant": "00000000-0000-0000-0000-000000000000",
      "startupObjectId": 70308,
      "startupObjectType": "Page",
      "breakOnError": "All",
      "launchBrowser": true
    }
  ]
}

Add the data and enum objects

Create src/WorkAreaEnums.al:

enum 70300 "Work Area Priority"
{
    Extensible = true;
    value(0; Normal) { Caption = 'Normal'; }
    value(10; High) { Caption = 'High'; }
}

enumextension 70301 "Work Area Priority Ext" extends "Work Area Priority"
{
    value(20; Critical) { Caption = 'Critical'; }
}

enum 70302 "Work Area Status"
{
    Extensible = false;
    value(0; Open) { Caption = 'Open'; }
    value(10; "In Review") { Caption = 'In review'; }
    value(20; Completed) { Caption = 'Completed'; }
}

Create src/WorkAreaTables.al:

table 70300 "Work Area Item"
{
    Caption = 'Work Area Item';
    DataClassification = CustomerContent;

    fields
    {
        field(1; "Entry No."; Integer) { DataClassification = SystemMetadata; }
        field(2; Title; Text[100]) { DataClassification = CustomerContent; NotBlank = true; }
        field(3; "Customer No."; Code[20])
        {
            DataClassification = CustomerContent;
            TableRelation = Customer."No.";
        }
        field(4; Priority; Enum "Work Area Priority") { DataClassification = CustomerContent; }
        field(5; Status; Enum "Work Area Status") { DataClassification = CustomerContent; }
        field(6; "Due Date"; Date)
        {
            DataClassification = CustomerContent;
            trigger OnValidate()
            begin
                if ("Due Date" <> 0D) and ("Due Date" < Today()) then
                    FieldError("Due Date", 'The due date can''t be earlier than today.');
            end;
        }
    }

    keys
    {
        key(PK; "Entry No.") { Clustered = true; }
        key(StatusPriority; Status, Priority) { }
    }
}

tableextension 70303 "Customer Work Area Ext" extends Customer
{
    fields
    {
        field(70300; "Work Area Note"; Text[100])
        {
            Caption = 'Work area note';
            DataClassification = CustomerContent;
        }
    }
}

table 70304 "Work Area Activity"
{
    Caption = 'Work Area Activity';
    DataClassification = SystemMetadata;

    fields
    {
        field(1; "Primary Key"; Code[10]) { DataClassification = SystemMetadata; }
        field(2; "Open Items"; Integer)
        {
            FieldClass = FlowField;
            CalcFormula = count("Work Area Item" where(Status = const(Open)));
            Editable = false;
        }
        field(3; "Critical Items"; Integer)
        {
            FieldClass = FlowField;
            CalcFormula = count("Work Area Item" where(Priority = const(Critical)));
            Editable = false;
        }
    }

    keys { key(PK; "Primary Key") { Clustered = true; } }
}

Add the task pages and Role Center

Create src/WorkAreaPages.al:

page 70305 "Work Area Item List"
{
    PageType = List;
    SourceTable = "Work Area Item";
    ApplicationArea = All;
    UsageCategory = Lists;
    CardPageId = "Work Area Item Card";
    Caption = 'Work Area Items';

    layout
    {
        area(Content)
        {
            repeater(Items)
            {
                field("Entry No."; Rec."Entry No.") { ToolTip = 'Specifies the stable item identifier.'; }
                field(Title; Rec.Title) { ToolTip = 'Specifies the work item title.'; }
                field("Customer No."; Rec."Customer No.") { ToolTip = 'Specifies the related customer.'; }
                field(Priority; Rec.Priority) { ToolTip = 'Specifies the review priority.'; }
                field(Status; Rec.Status) { ToolTip = 'Specifies the workflow status.'; }
                field("Due Date"; Rec."Due Date") { ToolTip = 'Specifies the due date.'; }
            }
        }
    }
}

page 70306 "Work Area Item Card"
{
    PageType = Card;
    SourceTable = "Work Area Item";
    ApplicationArea = All;
    Caption = 'Work Area Item';

    layout
    {
        area(Content)
        {
            group(General)
            {
                field("Entry No."; Rec."Entry No.") { Editable = false; ToolTip = 'Specifies the stable item identifier.'; }
                field(Title; Rec.Title) { ToolTip = 'Specifies the work item title.'; }
                field("Customer No."; Rec."Customer No.") { ToolTip = 'Specifies the related customer.'; }
                field(Priority; Rec.Priority) { ToolTip = 'Specifies the review priority.'; }
                field(Status; Rec.Status) { ToolTip = 'Specifies the workflow status.'; }
                field("Due Date"; Rec."Due Date") { ToolTip = 'Specifies the due date.'; }
            }
        }
    }
}

pageextension 70311 "Customer Card Work Area" extends "Customer Card"
{
    layout
    {
        addlast(General)
        {
            field("Work Area Note"; Rec."Work Area Note")
            {
                ApplicationArea = All;
                ToolTip = 'Specifies a note for the review work area.';
            }
        }
    }
}

page 70307 "Work Area Activities"
{
    PageType = CardPart;
    SourceTable = "Work Area Activity";
    ApplicationArea = All;
    Caption = 'Review activity';

    layout
    {
        area(Content)
        {
            cuegroup(Review)
            {
                field("Open Items"; Rec."Open Items")
                {
                    ToolTip = 'Specifies the number of open work items.';
                    DrillDownPageId = "Work Area Item List";
                }
                field("Critical Items"; Rec."Critical Items")
                {
                    ToolTip = 'Specifies the number of critical work items.';
                    DrillDownPageId = "Work Area Item List";
                }
            }
        }
    }

    trigger OnOpenPage()
    begin
        if not Rec.Get('') then begin
            Rec.Init();
            Rec."Primary Key" := '';
            Rec.Insert();
        end;
    end;
}

page 70308 "Work Area Role Center"
{
    PageType = RoleCenter;
    ApplicationArea = All;
    Caption = 'Work Area Reviewer';

    layout
    {
        area(RoleCenter)
        {
            part(Activities; "Work Area Activities") { ApplicationArea = All; }
            part(Summary; "Work Area Summary Part") { ApplicationArea = All; }
        }
    }

    actions
    {
        area(Embedding)
        {
            action(Items)
            {
                Caption = 'Work Area Items';
                ApplicationArea = All;
                RunObject = page "Work Area Item List";
            }
        }
        area(Processing)
        {
            action(Initialize)
            {
                Caption = 'Initialize Sample Data';
                ApplicationArea = All;
                Image = Setup;
                RunObject = codeunit "Work Area Sample Data";
            }
        }
    }
}

profile "Work Area Reviewer"
{
    Caption = 'Work Area Reviewer';
    RoleCenter = "Work Area Role Center";
    ProfileDescription = 'Reviews extension work area items.';
}

Add the control add-in contract

Create src/WorkAreaControlAddIn.al:

controladdin "Work Area Summary"
{
    StartupScript = 'src/controladdin/startup.js';
    Scripts = 'src/controladdin/workAreaSummary.js';
    StyleSheets = 'src/controladdin/workAreaSummary.css';
    RequestedHeight = 180;
    MinimumHeight = 140;
    MaximumHeight = 240;
    HorizontalStretch = true;
    VerticalStretch = true;

    event Ready();
    procedure RenderSummary(Payload: Text);
}

page 70310 "Work Area Summary Part"
{
    PageType = CardPart;
    SourceTable = "Work Area Activity";
    ApplicationArea = All;
    Caption = 'Priority summary';

    layout
    {
        area(Content)
        {
            usercontrol(SummaryControl; "Work Area Summary")
            {
                ApplicationArea = All;
                trigger Ready()
                begin
                    ControlIsReady := true;
                    SendSummary();
                end;
            }
            field(FallbackStatus; FallbackStatus)
            {
                ApplicationArea = All;
                Caption = 'Visualization status';
                Editable = false;
                ToolTip = 'Shows whether the optional browser visualization is ready.';
            }
        }
    }

    trigger OnOpenPage()
    begin
        if not Rec.Get('') then begin
            Rec.Init();
            Rec."Primary Key" := '';
            Rec.Insert();
        end;
        FallbackStatus := 'The standard cues remain available while the visualization loads.';
    end;

    local procedure SendSummary()
    var
        WorkItem: Record "Work Area Item";
        ItemObject: JsonObject;
        Items: JsonArray;
        Payload: JsonObject;
        PayloadText: Text;
    begin
        if not ControlIsReady then
            exit;

        WorkItem.SetCurrentKey(Status, Priority);
        WorkItem.SetRange(Status, "Work Area Status"::Open);
        if WorkItem.FindSet() then
            repeat
                Clear(ItemObject);
                ItemObject.Add('entryNo', WorkItem."Entry No.");
                ItemObject.Add('title', WorkItem.Title);
                ItemObject.Add('priority', Format(WorkItem.Priority));
                Items.Add(ItemObject);
            until WorkItem.Next() = 0;

        Payload.Add('version', 1);
        Payload.Add('items', Items);
        Payload.WriteTo(PayloadText);
        CurrPage.SummaryControl.RenderSummary(PayloadText);
        FallbackStatus := 'The visualization is ready. The standard cues remain available.';
    end;

    var
        ControlIsReady: Boolean;
        FallbackStatus: Text[100];
}

Create src/controladdin/workAreaSummary.js:

function RenderSummary(payload) {
    const root = document.getElementById('controlAddIn');
    root.replaceChildren();

    try {
        const message = JSON.parse(payload);
        const heading = document.createElement('h2');
        heading.textContent = 'Open work items';
        root.appendChild(heading);

        const list = document.createElement('ul');
        list.setAttribute('aria-label', 'Open work items by priority');
        message.items.forEach(function (item) {
            const row = document.createElement('li');
            const title = document.createElement('span');
            const priority = document.createElement('strong');
            title.textContent = item.title;
            priority.textContent = item.priority;
            row.append(title, priority);
            list.appendChild(row);
        });
        root.appendChild(list);
    } catch (error) {
        const status = document.createElement('p');
        status.setAttribute('role', 'status');
        status.textContent = 'The visual summary is unavailable. Use the standard cues and item list.';
        root.appendChild(status);
    }
}

Create src/controladdin/startup.js:

(function () {
    const root = document.getElementById('controlAddIn');
    const status = document.createElement('p');
    status.setAttribute('role', 'status');
    status.textContent = 'Loading the work item summary.';
    root.replaceChildren(status);

    Microsoft.Dynamics.NAV.InvokeExtensibilityMethod('Ready', [], false);
}());

Create src/controladdin/workAreaSummary.css:

#controlAddIn {
    box-sizing: border-box;
    color: #242424;
    font-family: "Segoe UI", sans-serif;
    min-height: 140px;
    padding: 8px;
}

#controlAddIn h2 {
    font-size: 1rem;
    margin: 0 0 8px;
}

#controlAddIn ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

#controlAddIn li {
    border-bottom: 1px solid #d1d1d1;
    display: flex;
    gap: 12px;
    justify-content: space-between;
    padding: 6px 0;
}

#controlAddIn strong {
    color: #005a9e;
}

Initialize sample data

Create src/WorkAreaSampleData.al:

codeunit 70312 "Work Area Sample Data"
{
    trigger OnRun()
    begin
        Initialize();
    end;

    procedure Initialize()
    begin
        InsertItem(703001, 'Review customer setup', "Work Area Priority"::High, "Work Area Status"::Open, Today() + 3);
        InsertItem(703002, 'Validate extension upgrade', "Work Area Priority"::Critical, "Work Area Status"::Open, Today() + 5);
        InsertItem(703003, 'Confirm page workflow', "Work Area Priority"::Normal, "Work Area Status"::"In Review", Today() + 7);
        Message('Sample work area data is ready.');
    end;

    local procedure InsertItem(EntryNo: Integer; ItemTitle: Text[100]; ItemPriority: Enum "Work Area Priority"; ItemStatus: Enum "Work Area Status"; DueDate: Date)
    var
        WorkItem: Record "Work Area Item";
    begin
        if WorkItem.Get(EntryNo) then
            exit;
        WorkItem.Init();
        WorkItem."Entry No." := EntryNo;
        WorkItem.Validate(Title, ItemTitle);
        WorkItem.Validate(Priority, ItemPriority);
        WorkItem.Validate(Status, ItemStatus);
        WorkItem.Validate("Due Date", DueDate);
        WorkItem.Insert(true);
    end;
}

Build, publish, and verify the work area

  1. Run AL: Download Symbols, then run AL: Package. Correct only baseline values if the compiler identifies a version mismatch.
  2. Press F5, authenticate to the online sandbox, and allow Visual Studio Code to publish the app.
  3. On the Work Area Reviewer page, select Initialize Sample Data.
  4. Verify that Open Items shows two and Critical Items shows one, then open Work Area Items.
  5. Open an item card, change its priority or status, and verify that a past due date produces a validation error.
  6. Return to the Role Center and verify that the browser summary renders after readiness while the standard cues remain usable.
  7. Open a customer card and verify that Work area note appears in the General group.

The exercise meets its acceptance criteria when the app compiles and publishes, all objects remain in 70300 through 70312, stable enum values remain 0, 10, and 20, sample initialization is repeatable, cue navigation works, and the page remains usable if the visualization displays its loading or unavailable state.

To clean up, open Extension Management, locate Extension Safe Work Area, and uninstall it. Select the option to delete extension data when the sandbox no longer needs the sample records.