Report extension object

APPLIES TO: Business Central 2021 release wave 1 (v18.0) and later

With the report extension object, you can extend existing report objects, similar to how you extend tables and pages. With report extensions, you can extend an existing report by:

  • Adding columns to existing data items in the report dataset
  • Adding new data items
  • Adding trigger implementations
  • Adding to request pages
  • Adding more report layouts, either to reflect new fields that are added with an extension, or simply adding new report layouts on an existing report dataset.

For a report to be extended, the Extensible property must be set to true, which is the default value. The value true, which means that reports by default can be extended, unless they explicitly have the Extensible property set to false. For more information, see Extensible Property.

Note

Extension objects can have a name with a maximum length of 30 characters.

Report extension layout

From Business Central 2022 release wave 1, report extensions can have one or more layouts defined. For more information, see Defining Multiple Report Layouts. The report layout of an existing report can't be extended, but new layouts can be added. To use an existing report as a starting point, you can download the layout from Business Central and include it in the extension project.

Layouts that are included in a report extension show up in Business Central as more layouts to the report. Layouts from a report extension are not automatically used when the extension is deployed. To use one of the new report layouts, go to the Report Layouts page in Business Central, and then choose the layout for the report in question as the new Default Layout.

Snippet support

Typing the shortcut treportext creates the basic layout for a report extension object when using the AL Language extension for Microsoft Dynamics 365 Business Central in Visual Studio Code.

Tip

Use Ctrl+Space to trigger IntelliSense and get assistance on code completion, parameter info, quick info, and member lists. For more information about snippets, see Syntax and snippets.

Report extension example

The following example illustrates a simplified table extension, which adds a new field to the Customer table, MyField. The report extension MyExtension then adds MyField and an extra field in original Customer table to the Customer - Top 10 List report, and it adds a new Excel layout to the report. The example also illustrates how a new field added to the report extension, can be modified using the OnBeforeAfterGetRecord trigger. For more information, see OnBeforeAfterGetRecord (Report Extension Data Set Modify) Trigger. For a list of triggers that can be used inside the modify section of a report, go to the Related information section.

For a more advanced example, see Report extension example.

Note

Inside the requestpage element, you cannot modify any properties.

Using the OnInitReport trigger is not supported for report extensions. The OnPreReport and OnPostReport triggers are run after the original report's equivalent triggers.

tableextension 50110 CustomerTableExt extends Customer
{
    fields
    {
        field(50100; MyField; Integer)
        {
            DataClassification = ToBeClassified;

        }
    }
}

reportextension 50110 MyExtension extends "Customer - Top 10 List"
{
    dataset
    {
        add(Integer)
        {
            // add existing field from base table to dataset
            column(fromBaseTable; Customer.GLN) { }
            // add field from table extending Customer
            column(fromBaseTableExt; Customer.MyField) { }
        }

        add(Customer)
        {
            // add a new field to the dataset
            column(netWeight; netWeight) { }
        }

        modify(Customer)
        {
            // modify the new, added field
            trigger OnBeforeAfterGetRecord()
            begin
                if (weightInPounds) then begin
                    netWeight := netWeight * 2.2;
                end else begin
                    netWeight := netWeight;
                end;
            end;
        }
    }

    requestpage
    {
        layout
        {
            addafter(Show)
            {
                // add field from table extension to request page
                field(fromBaseTableExt; Customer.myField) { }
            }
        }
    }

    // add additional report layouts to the report
    rendering
    {
        layout(MyExcelLayout)
        {
            Type = Excel;
            Caption = 'Top 10 customers (Excel)';
            Summary = 'Top 10 customers in my favorite analysis app: Excel';
            LayoutFile = 'Top10CustomersAsExcel.xlsx';
        }
    }

    trigger OnPreReport()
    begin
        // add code to run before the report is run, will be run after the original report's equivalent trigger
    end;

    trigger OnPostReport()
    begin
        // add code to run after the report is run, will be run after the original report's equivalent trigger
    end;

    var
        netWeight: Integer;
        weightInPounds: Boolean;

}

Tip

From the Business Central client, you can export report results as raw data to a Microsoft Excel file. The file contains all columns of the dataset, but without the layout applied. Use the file to help validate that the report returns the expected data, and to ensure that the report layout controls match the dataset value types. To export a report dataset to Excel, run the report and select the Send to > Microsoft Excel Document (data only) on the request page. For more information, see Working with Reports - Send to Excel.

Report extension example
Using request pages with reports
Creating an Excel layout report
Creating an RDL layout report
Creating a Word layout report
Adding help links from pages, reports, and XMLports
Page extension object
Page properties
Developing extensions
AL development environment

Report extension triggers
OnPostReport (Report Extension) Trigger
OnPreReport (Report Extension) Trigger
OnAfterAfterGetRecord (Report Extension Data Set Modify) Trigger
OnAfterPostDataItem (Report Extension Data Set Modify) Trigger
OnAfterPreDataItem (Report Extension Data Set Modify) Trigger
OnBeforeAfterGetRecord (Report Extension Data Set Modify) Trigger
OnBeforePostDataItem (Report Extension Data Set Modify) Trigger
OnBeforePreDataItem (Report Extension Data Set Modify) Trigger