Report Extension in AL

Overview of Microsoft Dynamics 365 Business Central

Report extensions in AL allow developers to customize standard Business Central reports without modifying the original report object. They exist to make reports extensible while preserving upgrade safety, exactly like table extensions and page extensions do for data and UI.

This page explains what report extensions are, why they exist, and how they are used in real implementations, with practical examples. The focus is on extending datasets, adding logic, and adjusting output behavior, not on designing layouts themselves.


Why Report Extensions Exist

Standard reports in Business Central are delivered and maintained by Microsoft. These reports often satisfy most requirements, but real businesses frequently need:

• Additional fields in printed documents
• Extra calculations
• Conditional output behavior
• Minor logic adjustments during report execution

Directly modifying a standard report would:

• Be overwritten during upgrades
• Break compatibility
• Increase maintenance cost

Report extensions exist to solve this problem by allowing safe, additive customization.

What Is a Report Extension?

A report extension is an AL object that extends an existing report at runtime. It does not replace the report and does not create a new one. Instead, it injects additional behavior into the standard report execution pipeline.

A report extension can:

• Add fields to the report dataset
• Add new dataitems
• Add or override report triggers
• Add additional layout files

A report extension cannot:

• Remove existing dataitems
• Redesign standard logic completely
• Replace posting behavior

When You Should Use a Report Extension

You should use a report extension when:

• You need extra data on a standard report
• The standard report logic is mostly correct
• The requirement must survive upgrades
• You want to reuse Microsoft’s report structure

Common examples include:

• Adding custom fields to Sales Invoice printouts
• Including additional totals or notes
• Adding company-specific information to documents

Basic Structure of a Report Extension

A report extension is defined using the reportextension object and references the report it extends.

Example: Structure of Report Extension

AL

reportextension 50140 SalesInvoiceExtension extends "Sales - Invoice"
{
}
    

The extends clause identifies the standard report being customized.

Extending the Dataset

One of the most common uses of report extensions is adding fields to the dataset so they can be used in layouts.

Example: Extending Reports

AL

reportextension 50140 SalesInvoiceExtension extends "Sales - Invoice"
{
    dataset
    {
        add(SalesInvoiceHeader)
        {
            column(CustomerCategory; "Customer Category")
            {
            }
        }
    }
}
    

This example:

• Extends the existing dataset
• Adds a custom field from the table
• Makes the field available for layouts

The base report remains untouched.

Adding Calculated Fields to the Dataset

Report extensions can also add calculated columns.

Example: Adding Calculated Fields

AL

dataset
{
    add(SalesInvoiceHeader)
    {
        column(InvoiceYear; Format("Posting Date", 0, ''))
        {
        }
    }
}
    

These calculated fields:

• Are evaluated during report execution
• Do not change stored data
• Are useful for grouping or display logic

Adding Report Triggers in Extensions

Report extensions allow you to add logic using triggers, but this logic must be report-specific and non-destructive.

Example: Report Triggers

AL

trigger OnPreReport()
begin
    // Initialization logic
end;
    

Appropriate uses include:

• Initializing variables
• Preparing temporary buffers
• Controlling conditional output

Core business logic should still reside in codeunits.

Adding Additional Layouts (High-Level)

Report extensions can add new layouts without removing standard ones.

Example: Adding Additional Layouts

AL

rendering
{
    layout(CustomInvoice)
    {
        Type = RDLC;
        LayoutFile = 'CustomInvoice.rdl';
    }
}
    

This allows:

• Company-specific layouts
• Country-specific formats
• Customer-specific documents

Layout design itself is a separate topic.

Report Extensions and Upgrade Safety

During an upgrade:

• Standard reports may change
• Report extensions are reapplied
• Custom fields and layouts remain intact

Because extensions only add behavior, they are resilient to platform changes.

Common Beginner Mistakes With Report Extensions

Developers often:

• Try to replace standard logic instead of extending it
• Add heavy business logic in report triggers
• Use report extensions when a new custom report is better
• Forget to add fields to the dataset before using them in layouts

Understanding the purpose of report extensions avoids these issues.

Summary

Report extensions in AL provide a safe and structured way to customize standard reports in Business Central. They allow developers to enhance reporting output and logic while preserving Microsoft’s base functionality and upgrade safety.

A well-designed report extension:

• Adds only required fields
• Keeps logic lightweight
• Uses dataset extensions correctly
• Survives upgrades cleanly

Understanding report extensions completes the reporting customization layer of AL development.

Hot Topics in Business Central

Next Steps in Business Central