Building and Extending Page Objects
Earn 25 points (50 with Pro) in two steps
- ① Read through the lesson — each section gets a ✓ as you scroll through it.
- ② When every section has a ✓, tap Complete lesson.
0 of 10 read · keep scrolling
✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro
Lesson: Building and Extending Page Objects in AL
Introduction: The Interface of Your Business Logic
In the world of business application development, specifically within the Business Central ecosystem, the Page object is the bridge between your complex database logic and the end user. While tables hold your data, pages provide the structure, layout, and interaction points that allow users to perform their daily tasks. Understanding how to build these objects from scratch and how to extend existing ones is the most fundamental skill a developer can acquire.
When you build a page, you are not just defining a set of fields on a screen; you are defining a workflow. You determine how a user navigates through information, what data they can edit, and how they trigger business processes. Because Business Central is a highly modular environment, you rarely start from a blank slate. You will frequently find yourself extending existing pages—adding a field here, a button there, or changing the visibility of a column—to meet specific customer requirements. This lesson explores the technical mechanics of AL (Application Language) page development, focusing on both new object creation and the art of object extension.
Not read yet
Part 1: Anatomy of a Page Object
Every page in AL is defined by a specific structure that separates the layout (how it looks) from the actions (what it does). A well-structured page file is easier to maintain, read, and debug.
The Layout Section
The layout section is where you define the visual components of your page. This includes containers, groups, repeaters, and individual fields. The hierarchy is strict: you must have a content area, which usually contains a repeater (for lists) or group (for cards), and within those, you place your field objects.
The Actions Section
The actions section defines the menu items that appear in the action bar at the top of the page. These can be grouped into categories like Processing, Reporting, or Creation. Each action is tied to a trigger, most commonly OnAction, where you place the logic that should execute when the button is clicked.
Callout: Page Types vs. Page Usage It is important to distinguish between the
PageTypeproperty and how the page is intended to be used. While you might create aListpage type, you can also use it as a lookup or a selection dialog. Always set thePageTypeto match the primary intent (e.g.,Card,List,Document,Worksheet) to ensure the platform applies the correct styling and responsive behavior.
Not read yet
Part 2: Building a New Page from Scratch
To create a new page, you start with the page object keyword, followed by an ID and a name. You must also link the page to a source table using the SourceTable property.
Step-by-Step: Creating a Simple Card Page
- Create a new file with the
.alextension. - Use the
tpagesnippet to generate the template. - Define the
PageTypeasCard. - Set the
SourceTableto the table you created. - Define the
layoutarea. - Define the
actionsarea.
page 50100 "Customer Interest Card"
{
PageType = Card;
SourceTable = "Customer Interest";
Caption = 'Customer Interest Card';
layout
{
area(Content)
{
group(General)
{
field(Code; Rec.Code)
{
ApplicationArea = All;
ToolTip = 'Specifies the unique code for the interest.';
}
field(Description; Rec.Description)
{
ApplicationArea = All;
ToolTip = 'Specifies a description of the interest.';
}
}
}
}
actions
{
area(Processing)
{
action(ClearInterest)
{
Caption = 'Clear Interest';
Image = Delete;
ApplicationArea = All;
trigger OnAction()
begin
Rec.Description := '';
Rec.Modify();
end;
}
}
}
}
Understanding Field Properties
When adding fields, you must always define the ApplicationArea. Without this, the field will simply not appear in the user interface, which is a common source of frustration for new developers. The ToolTip property is another mandatory requirement for accessibility and user guidance; it appears when the user hovers over the field.
Note: Always use the
Recprefix when referencing fields from the source table. While AL often allows you to omit it, usingRec.explicitly makes your code more readable and avoids ambiguity when you have local variables with similar names.
Not read yet
Part 3: Extending Existing Pages
Extensions are the lifeblood of Business Central development. Instead of modifying base application objects (which is impossible in modern development), you use pageextension objects to add functionality to existing pages.
The Syntax of Extension
An extension object targets a specific page by its name. You do not need to know the ID of the base page, only the name. You can add new fields to existing groups, add new groups, or add new actions to existing action bars.
pageextension 50101 "Customer Card Ext" extends "Customer Card"
{
layout
{
addafter("Address")
{
field("Interest Level"; Rec."Interest Level")
{
ApplicationArea = All;
Caption = 'Customer Interest Level';
}
}
}
actions
{
addlast(Processing)
{
action("Send Welcome Email")
{
ApplicationArea = All;
Caption = 'Send Welcome Email';
Image = Email;
trigger OnAction()
begin
// Logic to send email goes here
end;
}
}
}
}
Placement Options
When extending, you have specific control over where your changes appear:
addfirst: Places the element at the top of the container or group.addlast: Places the element at the bottom.addbefore(ControlName): Places the element immediately before the specified existing control.addafter(ControlName): Places the element immediately after the specified existing control.
Not read yet
Part 4: Best Practices for Page Development
1. Maintainability and Readability
Keep your page code clean. Do not put heavy business logic inside page triggers (OnInsert, OnModify, OnOpenPage). Instead, call functions in a codeunit. This keeps the page file focused on UI concerns and makes your logic testable and reusable.
2. User Experience (UX) Consistency
Always follow the standard look and feel of the application. If you are adding a new field to a Card page, place it in the appropriate group (e.g., General, Invoicing, Shipping). Do not create random groups unless necessary. Use standard captions and ensure the ToolTip is helpful.
3. Handling Visibility
Sometimes you only want a field to appear under specific conditions. You can use the Visible property, which accepts a boolean variable.
layout
{
field(SpecialField; Rec.SpecialField)
{
ApplicationArea = All;
Visible = ShowSpecialField;
}
}
trigger OnOpenPage()
begin
ShowSpecialField := UserSetup.IsAdmin();
end;
Warning: Be careful with the
Visibleproperty. If you set it tofalsebased on a condition, the user cannot see the field, but it still exists in the buffer. Do not use this for security purposes (like hiding sensitive financial data). Use actual permission sets for security; useVisibleonly for UI decluttering.
Not read yet
Part 5: Common Pitfalls and How to Avoid Them
The "Missing ApplicationArea" Trap
As mentioned earlier, the most common mistake is forgetting the ApplicationArea property. If a field, action, or part is defined but not assigned an ApplicationArea, the platform assumes it shouldn't be shown to the user. Always set it to All unless you have a specific reason to restrict it to a certain license level.
Over-complicating Page Triggers
Developers often put Rec.Modify() or Rec.Insert() calls directly inside OnAction triggers. While this works, it bypasses the standard validation logic defined in the table. Always try to let the platform handle the data operations through the UI, or if you must perform custom operations, call a procedure in a table or codeunit that handles the validation properly.
Hardcoding Values
Avoid hardcoding strings in Caption or ToolTip properties. Instead, use labels or text constants. This makes your application translation-ready for global markets.
// Bad
field(Name; Rec.Name) { Caption = 'Customer Name'; }
// Good
field(Name; Rec.Name) { Caption = CustomerNameLbl; }
// ... somewhere in the file
var
CustomerNameLbl: Label 'Customer Name';
Not read yet
Part 6: Advanced Page Techniques
Using Page Parts
A Page Part is a page that is embedded inside another page. This is commonly used for sub-pages (like Sales Lines inside a Sales Order). To create a part, you use the part keyword in the layout section.
area(Content)
{
part(SalesLines; "Sales Order Subform")
{
ApplicationArea = All;
SubPageLink = "Document No." = field("No.");
}
}
The SubPageLink property is vital. It establishes the relationship between the parent record and the child records. Without this, the sub-page will not filter its data correctly.
Handling Modality and Dialogs
Sometimes you need to prompt the user for input. Use the Page.RunModal function. This pauses the current page execution and opens a new page. The user must close the new page before returning to the original one.
trigger OnAction()
var
MyDialogPage: Page "My Dialog";
begin
if MyDialogPage.RunModal() = Action::OK then
begin
// Process the user input
end;
end;
Not read yet
Comparison: New Page vs. Page Extension
| Feature | New Page Object | Page Extension |
|---|---|---|
| Purpose | Creating entirely new UI screens | Modifying existing base app screens |
| Independence | Fully independent | Dependent on the base object |
| Complexity | Higher (requires full definition) | Lower (incremental changes) |
| Maintenance | Owns its own logic | Follows the lifecycle of the base page |
Callout: The "SubPageLink" Insight The
SubPageLinkproperty is one of the most powerful tools in your arsenal. It doesn't just filter; it creates a live, persistent link. When the parent record changes, the child part automatically updates its filter and re-fetches its data. Mastering this is the key to building complex, data-driven interfaces.
Part 7: Best Practices Checklist for Developers
- Naming Conventions: Always use clear, descriptive names for your pages. If you are extending, keep the name similar to the base page to maintain clear lineage.
- Performance: Do not put complex calculations or heavy database queries in the
OnAfterGetRecordtrigger. This trigger fires every time the user scrolls, which can cause significant performance degradation. - Accessibility: Always provide
ToolTipandCaptionfor every element. It makes the app usable for everyone and helps with automated testing tools. - Consistency: If the base page uses a specific field arrangement, follow that pattern. Do not reinvent the wheel by placing fields in non-standard locations.
- Testing: Always test your extensions in a sandbox environment. Check how your added fields behave when the page is resized or viewed on mobile devices.
Not read yet
Part 8: Troubleshooting Common Errors
Error: "The field does not exist"
This usually happens if you are trying to extend a page that doesn't have the source table you expect, or if you have a typo in the field name. Remember that when extending a page, you are referencing the fields of the base table. If you want to add a field that isn't in the base table, you must first create a tableextension to add the field to the table, then add the field to the page extension.
Error: "The control could not be found"
If you use addafter(ControlName), ensure that ControlName exactly matches the name of the control in the base application. You can find these names by using the "Inspect Pages and Data" tool in the Business Central client.
Page Not Appearing in Search
If you created a new page but it's not showing up when you search for it in the tell-me window, ensure you have set the UsageCategory and ApplicationArea properties on the page object.
page 50100 "My List"
{
PageType = List;
UsageCategory = Lists;
ApplicationArea = All;
// ...
}
Not read yet
Part 9: The Role of Profiles and Role Centers
While we focus on page objects, it is important to understand that your page will often be accessed through a Role Center. You can make your page accessible to users by adding it to a Profile or a RoleCenter. This is done via profile objects and pageextension objects that add actions to the Role Center.
Part 10: Final Thoughts on Page Lifecycle
A page in Business Central is not a static file; it is an active participant in the data lifecycle. It captures user intent, validates it, and translates it into database operations. When you build or extend a page, you are defining the constraints of that intent. By keeping your page objects lean, following naming conventions, and utilizing the power of extensions correctly, you ensure that your code remains professional, scalable, and easy to maintain over the long term.
Key Takeaways
- Separation of Concerns: Keep your AL pages focused on the UI. Move complex business logic into codeunits or table methods to ensure modularity and testability.
- Declarative Development: Leverage the built-in properties of the AL language (like
ApplicationArea,ToolTip, andCaption) to provide a consistent, accessible user experience. - Strategic Extension: When extending, use
addfirst,addlast,addbefore, andaddaftercarefully to maintain the logical flow of the original page design. - The
RecPrefix: Always use theRec.prefix to clarify that you are interacting with the source table of the page, preventing ambiguity in your code. - Performance Awareness: Avoid heavy processing in triggers that fire frequently, such as
OnAfterGetRecord, as this will negatively impact the user's perception of system speed. - Accessibility is Mandatory: Never skip
ToolTipandCaptionproperties. They are not optional; they are essential for professional, production-grade applications. - Always Use
SubPageLink: When building parent-child relationships between pages, strictly define theSubPageLinkto ensure data integrity and proper filtering between the two objects.
By mastering these concepts, you will move from simply "making things work" to "building high-quality, professional solutions" that integrate seamlessly into the Business Central environment. Remember that the best code is the code that someone else can pick up a year later and immediately understand. Keep your pages organized, your logic documented, and your UX consistent.
Not read yet
Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.
Spend your points to unlock exam-style practice questions
Spend points to unlock MB-820 exam-style practice questions.
Practice for MB-820