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 to a new report layout to reflect the new fields that are added with an extension

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, only substituted. 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 will show up in Business Central as built-in layouts. The layout in a report extension will not automatically be used when the report extension is deployed. To use the report extension layout, go to the Report Layout Selection page in Business Central, make sure to choose to use a built-in layout in the Selected layout field, and then choose the layout for the report in question from the Custom Layout Description drop-down box.

Snippet support

Typing the shortcut treportext will create the basic layout for a report extension object when using the AL Language extension in Visual Studio Code.

Tip

Use Ctrl+Space to trigger IntelliSense and get assistance on code completion, parameter info, quick info, and member lists.

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. For a more advanced example, see Report Extension Example. 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 See Also section.

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) { }
            }
        }
    }

    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, 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.

See Also

Report Extension Example
Request Pages
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
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