Replace and extend reports safely
Once a base report works, the required change determines whether you add to its contract or replace its execution. Choosing the smallest compatible mechanism reduces conflicts between extensions and preserves base application updates.
Choose extension or substitution
Use a report extension when the base report remains the correct report and the change is additive. A report extension can add columns to existing data items, add supported child or sibling data items, add request-page controls, implement supported extension triggers, and provide new layouts.
Use report substitution when a different report must run in place of the requested report. Substitution replaces behavior rather than changing the original object. It affects supported report invocation paths that raise the substitution event, so validate every way the report is called.
| Requirement | Preferred mechanism |
|---|---|
| Add a dataset column or request option | Report extension |
| Add an alternative layout for an existing dataset | Report extension |
| Preserve the base report and add supported processing | Report extension |
| Run a different report object for a specific base report | Report substitution |
| Redesign behavior beyond report-extension capabilities | Report substitution, after compatibility review |
The base report must be extensible for a report extension to target it. An extension can't use OnInitReport, and it can't modify existing request-page properties. It can add controls and supported trigger implementations, but it doesn't override the complete base report lifecycle.
Add report elements within extension boundaries
The following pattern adds a column to an existing data item and adds an option to the request page:
reportextension 70401 "Customer Review Ext" extends "Customer Balance Review"
{
dataset
{
add(Customer)
{
column(ExtensionNote; ExtensionNoteLbl) { }
}
}
requestpage
{
layout
{
addlast(Options)
{
field(IncludeExtensionNote; IncludeExtensionNote)
{
ApplicationArea = All;
Caption = 'Include extension note';
ToolTip = 'Specifies whether the extension note is included.';
}
}
}
}
var
IncludeExtensionNote: Boolean;
ExtensionNoteLbl: Label 'Extended report';
}
A report extension can declare new layouts in its rendering section. Those layouts become available after deployment, but Business Central doesn't select them automatically. A user or administrator selects an extension layout on the Report Layouts page, or extension installation code applies the intended layout.
Guard report substitution
Subscribe to OnAfterSubstituteReport in the Report Management codeunit to map a requested report ID to another report. Multiple extensions can subscribe to this event. If an earlier subscriber already assigns NewReportId, don't overwrite that choice.
codeunit 70402 "Report substitution"
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::ReportManagement,
'OnAfterSubstituteReport', '', false, false)]
local procedure SubstituteReport(ReportId: Integer; var NewReportId: Integer)
begin
if (NewReportId <> ReportId) and (NewReportId <> -1) then
exit;
if ReportId = Report::"Customer - List" then
NewReportId := Report::"Customer Balance Review";
end;
}
The guard respects a substitution already made by another extension. Also ensure that the replacement report doesn't lead back to the original through another subscriber. Test page actions, Tell Me, AL report methods, printing, and file output that matter to the solution.
For supported extension elements and current limitations, see Report extension object. For event behavior, see Substitute reports.