MSBA-352 · Lesson 4 of 12 · 21 min

Pages and page extensions

▶ Video coming soon A video version of this lesson is on the way.

Tables are invisible until a page shows them. When Joss published the first build with only tables, Callum opened UPDATE-TEST, searched for "warranty" and found nothing. "So where do I type?" he asked. This lesson builds the pages: a list and a card for registrations, a setup page, a part that shows a customer's warranties, and extensions to the standard item and customer pages so that the new fields appear where people already work.

Page types

Every page has a PageType that decides its layout and behaviour in the web client. Choosing the right type matters more than any field arrangement, because users already know how each type works from the standard product.

Page types and where the warranty app uses them.
PageTypeShowsStandard exampleWarranty app
ListMany records in rowsCustomersCNF Warranty Registrations
CardOne record with FastTabsCustomer CardCNF Warranty Registration
DocumentA header with linesSales OrderNot needed
ListPart, CardPartA list or card embedded in another pageSales order lines subpageCNF Customer Warranties FactBox
WorksheetEditable rows for batch workItem JournalNot needed
StandardDialog, ConfirmationDialogA small dialog with OK and CancelMany promptsVoid registration dialog
NavigatePageA wizard with Back and NextAssisted setup guidesA first-time setup guide (later)
RoleCenterA user's home pageBusiness ManagerNot needed
APIA REST endpoint, no user interfaceStandard v2.0 APIsLesson 8

A list page

The list page is where Callum and the sales team will find a warranty. Joss started with it because Business Central's search, called Tell Me, finds a page only if the page says it belongs in search.

The registrations list page.
namespace Quarrystone.CorbelFinch.Warranty;

page 50101 "CNF Warranty Registrations"
{
    Caption = 'Warranty Registrations';
    PageType = List;
    SourceTable = "CNF Warranty Registration";
    CardPageId = "CNF Warranty Registration";
    UsageCategory = Lists;
    ApplicationArea = All;
    Editable = false;

    layout
    {
        area(Content)
        {
            repeater(Registrations)
            {
                field("Serial No."; Rec."Serial No.") { }
                field("Item No."; Rec."Item No.") { }
                field("Customer No."; Rec."Customer No.") { }
                field("Customer Name"; Rec."Customer Name") { }
                field("Start Date"; Rec."Start Date") { }
                field("End Date"; Rec."End Date") { StyleExpr = EndDateStyle; }
                field(Status; Rec.Status) { }
            }
        }
        area(FactBoxes)
        {
            systempart(Links; Links) { }
            systempart(Notes; Notes) { }
        }
    }

    actions
    {
        area(Processing)
        {
            action(Void)
            {
                Caption = 'Void';
                Image = Cancel;
                ToolTip = 'Mark the selected warranty as void, for example when a machine is returned.';
                trigger OnAction()
                var
                    WarrantyMgt: Codeunit "CNF Warranty Mgt.";
                begin
                    WarrantyMgt.VoidRegistration(Rec);
                end;
            }
        }
        area(Promoted)
        {
            actionref(Void_Promoted; Void) { }
        }
    }

    trigger OnAfterGetRecord()
    begin
        EndDateStyle := '';
        if (Rec.Status = Rec.Status::Active) and (Rec."End Date" < CalcDate('<+30D>', Today())) then
            EndDateStyle := 'Attention';
    end;

    var
        EndDateStyle: Text;
}

The structure is the same on every page. The header properties connect the page to its SourceTable, name the card page that opens when a user selects a row, and decide whether the page appears in search (UsageCategory) and in which experience (ApplicationArea). The layout section has areas: Content for the main fields, with a repeater for rows on a list, and FactBoxes for the side pane. The actions section has areas for Processing, Navigation, Reporting and Promoted, where an actionref puts a copy of an action on the action bar.

Several things happen without code. Field captions come from the table, so Joss did not repeat them. Tooltips should be set on every field and action; Noor's rule was that a tooltip answers "what is this for" in one sentence, and UICop warns when one is missing. And because the table has a lookup to Customer, the Customer No. column shows a lookup arrow automatically.

The OnAfterGetRecord trigger runs for each row as it is read. Joss used it to set a style: warranties that end within 30 days show in the Attention style, so a café on the phone about a grinder whose warranty ends next week is handled carefully. The Rec variable always refers to the current record of the page's source table.

A card page

The card shows one registration with its fields grouped on FastTabs. Joss put the warranty facts on a General tab and the source of the registration (shipment, item, customer) on a Source tab, with a ListPart for the registration's claims at the bottom.

The registration card with two FastTabs and a claims part.
page 50102 "CNF Warranty Registration"
{
    Caption = 'Warranty Registration';
    PageType = Card;
    SourceTable = "CNF Warranty Registration";
    ApplicationArea = All;
    InsertAllowed = false;
    DeleteAllowed = false;

    layout
    {
        area(Content)
        {
            group(General)
            {
                Caption = 'General';
                field("Serial No."; Rec."Serial No.") { Editable = false; }
                field("Item No."; Rec."Item No.") { Editable = false; }
                field("Start Date"; Rec."Start Date") { }
                field("End Date"; Rec."End Date") { }
                field(Status; Rec.Status) { Editable = false; }
            }
            group(Source)
            {
                Caption = 'Source';
                field("Customer No."; Rec."Customer No.") { Editable = false; }
                field("Customer Name"; Rec."Customer Name") { }
                field("Shipment No."; Rec."Shipment No.") { Editable = false; }
            }
            part(Claims; "CNF Warranty Claims Part")
            {
                SubPageLink = "Registration Entry No." = field("Entry No.");
            }
        }
    }
}

InsertAllowed and DeleteAllowed are off because registrations are created by code when shipments post (lesson 6) and are voided rather than deleted. Callum can still correct the dates, for example when a manufacturer extends a warranty after a recall. The SubPageLink property filters the claims part to the current registration, the same way a sales order's lines are filtered to its header.

Page extensions

The warranty period must be set on the item card, and a café's warranties should be visible on the customer card. Those pages belong to Microsoft, so Joss wrote page extensions. A page extension can add fields, groups, parts and actions, change some properties of existing controls, and add triggers. It places new controls relative to existing ones with addafter, addbefore, addfirst and addlast, and changes existing controls with modify.

A wireframe of the Item Card. The Item Tracking FastTab shows the standard field Item Tracking Code, followed by two new fields highlighted in a different colour: Warranty Period and Register Warranty, labelled addafter Item Tracking Code. A second wireframe of the Customer Card shows a FactBox pane with a new Customer Warranties part, labelled addfirst FactBoxes, and a new action Warranties in the Related menu.
Where the page extensions place new controls on the Item Card and Customer Card.
Page extensions for the Item Card and Customer Card.
namespace Quarrystone.CorbelFinch.Warranty;

using Microsoft.Inventory.Item;
using Microsoft.Sales.Customer;

pageextension 50100 "CNF Item Card" extends "Item Card"
{
    layout
    {
        addafter("Item Tracking Code")
        {
            field("CNF Register Warranty"; Rec."CNF Register Warranty")
            {
                ApplicationArea = All;
                ToolTip = 'Specifies whether shipments of this item create warranty registrations.';
            }
            field("CNF Warranty Period"; Rec."CNF Warranty Period")
            {
                ApplicationArea = All;
                ToolTip = 'Specifies how long the warranty lasts, for example 24M for 24 months.';
                Editable = Rec."CNF Register Warranty";
            }
        }
    }
}

pageextension 50101 "CNF Customer Card" extends "Customer Card"
{
    layout
    {
        addfirst(FactBoxes)
        {
            part(CNFWarranties; "CNF Customer Warranties")
            {
                ApplicationArea = All;
                SubPageLink = "Customer No." = field("No.");
            }
        }
    }
    actions
    {
        addlast(navigation)
        {
            action(CNFWarrantiesAction)
            {
                ApplicationArea = All;
                Caption = 'Warranties';
                Image = ServiceItem;
                ToolTip = 'View warranty registrations for this customer.';
                RunObject = page "CNF Warranty Registrations";
                RunPageLink = "Customer No." = field("No.");
            }
        }
    }
}

Finding the right anchor is the practical skill. The anchor in addafter is the control name in the standard page's source, not the caption a user sees. Joss found "Item Tracking Code" by opening the page in the browser and using Page Inspection (Ctrl+Alt+F1), which shows the page and table behind any screen, the fields, and which extensions have added to it. The AL Explorer in Visual Studio Code and Go to Definition on the extended page name show the same information from the code side.

Page extensions cannot remove standard controls. They can hide one with modify and Visible = false, but Noor discouraged it: a field hidden by code cannot be brought back by a user, and it hides the field for every user in every profile. Hiding fields for particular roles is better done with profiles and page customizations, or simply by users personalizing their own pages.

Personalization, customization and extension

Business Central offers three ways to change what a page shows, and each belongs to a different person.

Three ways to change a page.
WayWho does itScopeWhere it lives
PersonalizationAny userTheir own view of a pageUser settings, no code
Profile customizationAn administratorEvery user with that profile (role)Tenant data, or a profile and pagecustomization object in AL
Page extensionA developerEvery user of the pageAn extension

Callum had already customized the Sales Order Processor profile for the sales team in the foundations course. Joss's page extensions add data that did not exist before; they do not rearrange what Callum has already arranged. A profile object in AL defines a role with its Role Centre, and a pagecustomization object adjusts pages for that profile; marketplace apps ship them so a whole role arrives ready to use, but Corbel & Finch's roles are maintained by Callum in the client.

FactBoxes and parts

A FactBox is a small part in the pane on the right of a card or list. Joss's CNF Customer Warranties part is a ListPart that shows a customer's active warranties with serial number, item and end date, filtered by the SubPageLink on the customer card extension. Parts are pages too, with their own source table and layout. Because parts load whenever the main page does, Noor reminded Joss to keep them light: a handful of fields, no heavy calculations, and FlowFields only when they are cheap.

Views on list pages

A list page can define views, named filters that appear as tabs above the list. Joss added two to the registrations list: Active and Expired, each filtered on Status. Ending soon was harder, because a view's filter is fixed text rather than a date calculated each day; the Attention style on the End Date column covers that need instead. Users can save their own views too, but shipping the common ones means the sales team sees them from day one.

Views on the registrations list page.
    views
    {
        view(Active)
        {
            Caption = 'Active';
            Filters = where(Status = const(Active));
        }
        view(Expired)
        {
            Caption = 'Expired';
            Filters = where(Status = const(Expired));
        }
    }

Worked problem

Placing a field on a standard page

Callum wants the warranty end date for a serial number visible on the Posted Sales Shipment page, next to each line. What does Joss need to decide?

Show solution
  1. Which page: the posted shipment lines are a subpage, Posted Sales Shpt. Subform, so the extension extends that page, not the header page.
  2. Which data: a shipment line can carry several serial numbers, so a single end date per line does not fit. A line action that opens the registrations filtered to the shipment and line is a better design.
  3. Which anchor: use Page Inspection on the lines to find the control names, then addlast to the line actions.
  4. Which permission: users who see posted shipments need read access to registrations (lesson 10).

Answer: Extend the lines subpage with an action that opens filtered registrations, because one line can hold several serial numbers.

Actions in depth

Actions are how users make things happen, and Business Central sorts them into areas that users already know. Processing holds actions that change data, such as Void. Navigation holds actions that open related information, such as Warranties on the customer card. Reporting holds reports, so the certificate action lives there on the registrations list. Creation holds actions that start new documents. The Promoted area does not define actions at all; it places references to existing actions on the action bar, optionally grouped, so that the most common ones are one click away.

An action can open an object without code using RunObject and RunPageLink, as the customer card extension does, or run code in its OnAction trigger. Noor's rule from lesson 5 applies: OnAction calls a codeunit procedure and does little else. Every action needs a caption, a tooltip and an Image from the standard image library, so that it looks like the rest of the product. Actions that open a dialog before doing anything should set Ellipsis = true, which adds the familiar three dots to the caption.

Notifications instead of messages

Pages can warn users without interrupting them. A Notification is the yellow bar that appears at the top of a page, with a message and optional actions. Joss used one on the registration card: if a warranty ends within 30 days, a notification says so and offers an action that opens the ending-soon report. Unlike Message, a notification does not stop the user, does not need a click, and does not break when the page is opened by code. Notifications are also the right answer to the lesson 6 example, where Callum wanted a warning about customers with many active warranties.

A page notification on the registration card.
    trigger OnAfterGetCurrRecord()
    var
        EndingSoon: Notification;
    begin
        if (Rec.Status = Rec.Status::Active) and (Rec."End Date" < CalcDate('<+30D>', Today())) then begin
            EndingSoon.Message(StrSubstNo(EndingSoonMsg, Rec."End Date"));
            EndingSoon.Scope := NotificationScope::LocalScope;
            EndingSoon.Send();
        end;
    end;

    var
        EndingSoonMsg: Label 'This warranty ends on %1.', Comment = '%1 = end date';

Usability checks before Callum sees a page

Noor gave Joss a short list to run through before publishing any page to UPDATE-TEST. Does the page open from search? Does every field and action have a tooltip that says what it is for? Are the most used fields on the first FastTab, so that a user on a small screen sees them without scrolling? Are editable and read-only fields obvious? Does the page work with the keyboard alone? Does it look right in the phone layout of the mobile app, where FastTabs collapse and FactBoxes move? UICop catches some of these, but most need a person to click through. Joss found that the claims part was unusable on a phone because it had nine columns, and cut it to four, with the rest on the claim card.

Pages for setup and first use

The warranty setup table from lesson 3 needs a page too. Setup pages follow a standard pattern: a Card page with InsertAllowed and DeleteAllowed set to false, and an OnOpenPage trigger that creates the single setup record if it is missing, so the page never opens empty. UsageCategory = Administration puts it in search under administration pages, where Callum looks for setup. Joss added the claim window and a default warranty period for new warranty items, each with a tooltip explaining the effect in business terms.

Microsoft also offers assisted setup, a list of guided setup pages that new customers work through, and an app can register its own guide, built as a NavigatePage with Back, Next and Finish buttons. For a per-tenant extension with one customer and one administrator, Noor judged a guide unnecessary: Callum would set up the app once, with Joss beside him. A marketplace app installed by strangers would need one. Joss noted the idea for the day the warranty app might be offered to Quarrystone's other coffee and equipment customers.

Common mistakes

  • MistakeForgetting UsageCategory and ApplicationArea on a new list page.

    InsteadSet both so Tell Me can find the page.

  • MistakeAnchoring addafter on the caption users see.

    InsteadAnchor on the control name; find it with Page Inspection or the page source.

  • MistakeHiding standard fields with a page extension.

    InsteadLeave hiding to profiles and personalization.

  • MistakeLeaving tooltips empty.

    InsteadGive every field and action a one-sentence tooltip.

  • MistakeAllowing users to insert and delete registrations on the card.

    InsteadCreate registrations from posting and void them with an action.

Summary and key terms

  • PageType decides layout and behaviour; List, Card, ListPart and API pages cover most needs.
  • A page has properties, a layout with areas and groups, actions with promoted action references, and triggers.
  • UsageCategory and ApplicationArea make a page searchable.
  • Page extensions add fields, parts and actions with addafter, addbefore, addfirst, addlast and modify.
  • Personalization belongs to users, profile customization to administrators and page extensions to developers.
  • FactBoxes, parts and views make extension data visible where people already work.
SourceTable
The table a page shows.
Repeater
The control that shows rows on a list or part.
FactBox
A small part in the pane beside a card or list.
Page extension
An object that adds controls and actions to an existing page.
actionref
A reference that promotes an existing action to the action bar.
Page Inspection
A client tool that shows the page, table, fields and extensions behind a screen.
Profile
A role that determines a user's Role Centre and page customizations.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Why are InsertAllowed and DeleteAllowed off on the registration card?

    Show answer

    Registrations are created by code when shipments post and are voided, not deleted, so the record stays as evidence.

  2. How did Joss find the control name Item Tracking Code?

    Show answer

    With Page Inspection in the browser, or from the standard page source through the AL Explorer or Go to Definition.

  3. What does SubPageLink do on the customer card FactBox?

    Show answer

    It filters the part to registrations whose Customer No. equals the customer card's No.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz