Developing Report Request Pages
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
Developing Report Request Pages in AL
Introduction: The Gateway to Data Interaction
In the world of business application development, particularly when working with ERP systems like Dynamics 365 Business Central, reports are the primary mechanism for transforming raw transactional data into actionable insights. However, a report that simply dumps every record in a database onto a page is rarely useful. Users need the ability to filter, sort, and configure how that data is presented before it is generated. This is where the Report Request Page comes into play.
The Request Page serves as the user interface for your reports. It is the modal window that appears immediately after a user clicks "Print" or "Preview" but before the report actually executes its logic. By allowing users to specify date ranges, select specific customers, or toggle optional calculations, the Request Page transforms a static document into a dynamic tool. Understanding how to build these pages effectively is a core skill for any developer, as it directly impacts the usability and performance of your reporting suite. Without a well-designed Request Page, users are forced to deal with data overload, which leads to frustration and inefficient workflows.
This lesson explores the technical architecture of AL (Application Language) report objects, focusing specifically on the requestpage block. We will examine how to define fields, organize layouts, implement validation logic, and ensure that your reports provide a clean, intuitive experience for end-users.
Not read yet
The Anatomy of an AL Report Request Page
An AL report is composed of several distinct parts, but the requestpage block is the only one that interacts directly with the user before the report process begins. Structurally, the requestpage sits at the same level as the dataset and rendering sections within a report object.
When you define a request page, you are essentially building a specialized form. Unlike standard pages, which are designed for data entry and navigation, request pages are transient. They exist only to collect parameters that will be passed into the report's OnPreReport or OnPreDataItem triggers.
The Structure of the RequestPage Block
The basic syntax for a request page looks like this:
report 50100 "My Sales Report"
{
UsageCategory = ReportsAndAnalysis;
ApplicationArea = All;
dataset
{
// Data items go here
}
requestpage
{
layout
{
area(Content)
{
group(Options)
{
field(StartDate; StartDate)
{
ApplicationArea = All;
Caption = 'Start Date';
}
}
}
}
}
var
StartDate: Date;
}
In this example, we define a variable StartDate in the report's global scope. We then expose that variable on the request page using a field control. When the user clicks "Run," the value they entered into that field is stored in the StartDate variable, which the report can then use to filter its data items.
Callout: Variables vs. Table Fields You might wonder whether to use report variables or table fields on a request page. Using table fields (e.g.,
field(CustomerNo; Customer."No.")) is often discouraged unless you are performing a complex lookup. Generally, it is better practice to declare custom variables in the report object and map them to the request page. This decouples the report logic from specific table structures and makes it easier to manage state without accidentally modifying actual database records.
Not read yet
Designing Effective Request Page Layouts
A well-organized request page helps users understand what options are available and how they affect the final output. The layout is defined within the layout section, utilizing area(Content) to define the main body of the page. Within that, you can use group controls to organize fields logically.
Organizing with Groups and Captions
Grouping fields is essential for readability. If your report has many parameters, throwing them all into one list will overwhelm the user. Instead, use groups to categorize settings by function. For example, you might have a "Filters" group for date ranges and customer numbers, and an "Options" group for toggles like "Include Details" or "Print in Summary Mode."
layout
{
area(Content)
{
group(General)
{
Caption = 'General Settings';
field(IncludeDetails; IncludeDetails)
{
ApplicationArea = All;
Caption = 'Include Detailed Lines';
}
}
group(Filters)
{
Caption = 'Data Filters';
field(PostingDate; PostingDate)
{
ApplicationArea = All;
Caption = 'Posting Date';
}
}
}
}
Best Practices for Field Placement
- Logical Flow: Place the most frequently used or most important filters at the top.
- Concise Captions: Keep captions short and clear. Avoid technical jargon; use terms that business users understand.
- Application Areas: Always define the
ApplicationAreaproperty. If you omit this, your fields may not appear, as the system will default to hiding them to comply with the user's licensing or personalization settings. - Tooltips: Never neglect the
ToolTipproperty. It is the primary way to provide context to the user without cluttering the UI.
Not read yet
Implementing Interaction and Logic
The power of a request page lies in its ability to react to user input. While the page itself is static, you can implement triggers to validate data or change the state of the page dynamically.
Using the OnValidate Trigger
The OnValidate trigger on a field is the most common place to perform checks. For example, if you have a "Start Date" and "End Date" field, you should validate that the end date is not before the start date.
field(EndDate; EndDate)
{
ApplicationArea = All;
Caption = 'End Date';
trigger OnValidate()
begin
if (EndDate < StartDate) and (EndDate <> 0D) then
Error('The end date cannot be before the start date.');
end;
}
Dynamic Visibility (The Visible Property)
Sometimes, a field should only be visible based on a previous choice. For instance, if you have a checkbox for "Include Detailed Lines," you might only want to show a "Sort By" option if that checkbox is enabled. You can control this using the Visible property, which can be linked to a boolean variable.
field(IncludeDetails; IncludeDetails)
{
ApplicationArea = All;
trigger OnValidate()
begin
// The page will automatically refresh if the UI is bound to these variables
end;
}
field(SortOption; SortOption)
{
ApplicationArea = All;
Visible = IncludeDetails; // Only visible if IncludeDetails is true
}
Note: When using dynamic visibility, remember that the page state is updated during the interaction process. Ensure that your logic is efficient. Avoid performing heavy database queries inside
OnValidatetriggers, as this will make the request page feel sluggish and unresponsive.
Not read yet
Handling Data Filters: The Automatic Approach
Business Central provides a powerful feature for reports: automatic data filtering. When you add a DataItem to your report, the system automatically creates a "Filter" tab on the request page. This allows users to apply filters to the table records without you needing to write a single line of code.
Managing Auto-Filters
You can control which fields appear in the auto-filter section by setting the RequestFilterFields property on the DataItem.
dataset
{
dataitem(Customer; Customer)
{
RequestFilterFields = "No.", "Customer Posting Group", "Country/Region Code";
}
}
This is significantly more efficient than manually creating fields for every possible filter. It allows users to leverage the standard Business Central filter syntax (e.g., 1000..2000 for ranges, | for OR conditions, <>1000 for exclusions).
When to Use Manual vs. Auto-Filters
| Feature | Manual Fields (Variables) | Auto-Filters (RequestFilterFields) |
|---|---|---|
| Primary Use | Custom logic, toggles, parameters | Filtering records on the DataItem |
| Control | High - you define the UI and validation | Low - system-managed interface |
| Complexity | Higher - requires coding | Lower - declarative property |
| User Experience | Specific to the report's business logic | Standardized, familiar to BC users |
Always prefer RequestFilterFields for filtering data items. Reserve manual variables for inputs that influence the report's behavior (e.g., "Print in Color," "Include Zero Balances," "Language Selection") rather than the selection of the data itself.
Not read yet
Advanced Request Page Techniques
As you move beyond basic reporting, you will encounter scenarios where standard functionality isn't enough. Perhaps you need to perform a lookup against a custom table, or you need to pre-fill the request page with default values based on the user's settings.
Implementing Lookup Logic
To allow a user to select a value from a lookup table (e.g., selecting a specific Department), you can use the OnLookup trigger on a field.
field(DeptCode; DeptCode)
{
ApplicationArea = All;
trigger OnLookup(var Text: Text): Boolean
var
Dept: Record Department;
begin
if Page.RunModal(Page::"Department List", Dept) = Action::LookupOK then
DeptCode := Dept.Code;
end;
}
This snippet opens a standard list page, allows the user to pick a record, and updates the variable in your report object. This is a clean, professional way to handle inputs that require referential integrity.
Pre-populating Defaults with OnOpenPage
The OnOpenPage trigger is the perfect place to set initial values for your request page fields. If you want a report to default to the "Current Month" or "Previous Month," you calculate those dates here.
trigger OnOpenPage()
begin
if StartDate = 0D then
StartDate := CalcDate('<-CM>', WorkDate());
if EndDate = 0D then
EndDate := WorkDate();
end;
Warning: Avoid Over-Engineering A common mistake is to make the request page too complex. If you find yourself adding dozens of fields, tabs, and complex validation logic, consider whether the report is trying to do too much. A report should have a single, clear purpose. If it requires 20 parameters to configure, it might be better to split it into two separate reports or use a dedicated "Setup" page to store preferences rather than asking the user to re-enter them every time.
Not read yet
Best Practices and Industry Standards
Developing reports is a balance between technical capability and user experience. To ensure your reports are maintainable and user-friendly, adhere to these industry standards:
1. Consistent UI Conventions
If your users are used to standard Business Central reports, they expect to see the "Filter" tab first, followed by "Options." Do not deviate from this unless there is a very strong reason. Keep your custom options in the "Options" group, and ensure they follow the same stylistic patterns as native Microsoft reports.
2. Performance Considerations
The requestpage runs on the client side, but the logic inside triggers often interacts with the server. Avoid calling Record.FindSet() or other heavy operations inside a trigger that fires frequently. If you need to populate a dropdown list, do it once in OnOpenPage and store the result in a temporary table or a list variable.
3. Localization and Captions
Always use Caption properties for every field. Never rely on the name of the variable to serve as the label. Additionally, if your report is intended for an international audience, ensure that your captions are wrapped in labels or handled through standard translation files (.xlf). This ensures your report is ready for multi-language deployments.
4. Error Handling
When a user provides invalid input, use the Error() function to stop execution and display a clear message. Do not leave the user guessing why the report isn't running. A good error message tells the user exactly what is wrong and how to fix it (e.g., "The Start Date must be earlier than the End Date. Please adjust your selection.").
5. Documenting the Request Page
Since the request page is the primary interface, document it. Use the ToolTip property to explain what each field does. If a field is obscure, mention the impact of changing its value in the tooltip. This reduces the number of support tickets you will receive from confused end-users.
Not read yet
Common Pitfalls and How to Avoid Them
Even experienced developers fall into traps when building request pages. Here are a few common issues and how to navigate them.
The "Ghost Variable" Problem
A common mistake is forgetting to initialize variables. If you have a field bound to a variable, and that variable is not initialized, it will show its default value (e.g., 0 for integers, 0D for dates). If your report logic depends on this value, you might get unexpected results. Always ensure your variables are in a valid state before the report starts processing.
Over-Filtering the Dataset
Sometimes, developers add RequestFilterFields to every single field in a table. This leads to a cluttered request page that is difficult to navigate. Only expose the fields that are actually relevant for filtering. If a user needs to filter by a obscure field, they can always use the "Add Filter" button in the standard filter interface.
Ignoring the "Reset" Requirement
Users often want to run a report, then immediately run it again with slightly different parameters. If your request page keeps the previous values, that is usually helpful. However, if your report logic relies on specific state variables that change, you must ensure that your OnOpenPage or OnInitReport triggers handle the state correctly. If the user expects a "fresh" start, make sure you provide a way to clear the filters.
Forgetting the "ApplicationArea"
As mentioned before, failing to set ApplicationArea = All is the single most common reason why fields do not appear on a request page. If you are working in a specific industry solution, you might need to use a specific application area, but for general reports, All is the standard.
Not read yet
Practical Example: A Comprehensive Sales Summary Report
Let’s put it all together. Imagine you are building a Sales Summary report. The user needs to:
- Select a date range.
- Choose whether to include only "Posted" invoices or "Open" orders.
- Select a specific sales person.
Here is how you would structure the requestpage for this scenario:
report 50101 "Sales Summary Report"
{
UsageCategory = ReportsAndAnalysis;
ApplicationArea = All;
dataset
{
dataitem(SalesHeader; "Sales Header")
{
RequestFilterFields = "Posting Date", "Salesperson Code";
trigger OnPreDataItem()
begin
if StartDate <> 0D then
SetFilter("Posting Date", '>=%1', StartDate);
if EndDate <> 0D then
SetFilter("Posting Date", '<=%1', EndDate);
if not IncludeOpenOrders then
SetRange(Status, Status::Released);
end;
}
}
requestpage
{
layout
{
area(Content)
{
group(Options)
{
Caption = 'Report Options';
field(StartDate; StartDate)
{
ApplicationArea = All;
Caption = 'Start Date';
}
field(EndDate; EndDate)
{
ApplicationArea = All;
Caption = 'End Date';
}
field(IncludeOpenOrders; IncludeOpenOrders)
{
ApplicationArea = All;
Caption = 'Include Open Orders';
}
}
}
}
}
var
StartDate: Date;
EndDate: Date;
IncludeOpenOrders: Boolean;
}
In this example, we use the requestpage to collect the parameters, and then we use the OnPreDataItem trigger to translate those parameters into actual filters on the SalesHeader table. This keeps the logic separated: the request page handles the UI, and the data item handles the data retrieval.
Not read yet
Summary and Key Takeaways
Building effective Report Request Pages is about understanding the balance between flexibility and simplicity. You want to give the user enough control to get the data they need, without overwhelming them with unnecessary configuration options.
Key Takeaways
- Decouple Logic: Always separate your UI variables on the request page from the underlying data filtering logic. Use the
requestpagefor user input and theOnPreDataItemorOnPreReporttriggers to apply those inputs to your datasets. - Leverage Auto-Filters: Do not reinvent the wheel. Use
RequestFilterFieldsfor standard record filtering. It provides a familiar, powerful interface that users already know how to use. - Prioritize Usability: Use
groupcontrols to organize your request page logically. Always includeCaptionandToolTipproperties for every field to ensure the report is intuitive and accessible. - Mind the Application Area: Always define the
ApplicationAreaproperty for your fields. Without it, your fields will be invisible to the user, leading to confusing bugs where the report appears to be "missing" functionality. - Validate Early: Use the
OnValidatetrigger to catch user input errors immediately. Providing instant feedback is far better than having the report crash during execution. - Keep It Focused: A report should have a clear goal. If your request page is becoming too large, it is a sign that you should split the report into multiple, more focused objects.
- Consistent Formatting: Follow standard Business Central design patterns. Users appreciate consistency, and adhering to the established UI conventions makes your custom reports feel like a native part of the system.
By following these principles, you will create reports that are not only functional but also a joy for users to interact with. A well-designed request page is often the difference between a report that is ignored and a report that becomes a cornerstone of the user's daily workflow. Remember that the code you write today is the interface someone else will use tomorrow—make it clear, make it efficient, and make it predictable.
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