Add an RDLC layout to a report

Completed

To create an RDLC layout report, you need to use Visual Studio Report Designer or Microsoft SQL Server Reporting Services Report Builder.

RDLC layouts can result in slower performance with document reports, regarding actions that are related to the user interface (for example. like sending emails) compared to Word layouts. When developing layouts for document reports, we recommend that you design Word layouts instead of RDLC. With Word layouts, reports aren't impacted by the security constraints on sandbox app domains like they are with RDLC layouts. From a service perspective, RDLC layouts aren't trusted, so they will run in a sandbox app domain that only lives for the current report invocation.

The system requirements for Business Central list the supported versions:

  • Report Builder for SQL Server 2016

  • Visual Studio 2017 or 2019 with Microsoft RDLC Report Designer for Visual Studio

Make sure that you download and install the required software before you start to develop the report layout(s).

With RDLC layouts, you can add useful features to your report layouts such as:

  • Links from a field on a report to a page or another report.

  • Images and graphs.

Generally, you'll display most data in the body of a report, and you will use the header to display information before any dataset fields are displayed. For example, you can display a report title, company, and user information in the header of a report.

Headers and footers in client report definition (RDLC) report layouts have the following limitations:

  • From the header, you can't refer to group-specific information in the body.

  • You can have only one report header, one body, and one report footer in a report.

  • You can have group headers and footers and table headers and footers.

In AL, you have the option of defining multiple layouts for one report in code. This means that you can offer multiple versions of a layout for different purposes. Defining multiple layouts applies to both report objects, and report extension objects. The layouts can be of different types, meaning that you can have, for example, a Word layout and an Excel layout for one report, or multiple Excel layouts for one report. This enables creating report extensions that only add layouts to an existing report and packaging it as an extension .al file.

Let’s look at the following report object:

report 50105 ExampleRDLCLayout
{
    Caption = 'ExampleRDLCLayout';
    UsageCategory = ReportsAndAnalysis;
    ApplicationArea = All;
    DefaultRenderingLayout = Example_RDLCLayout;

    dataset
    {
        dataitem(Customer; Customer)
        {
            column(CustomerNo; "No.") { }
            column(CustomerName; Name) { }
            column(City; City) { }
            column(BalanceLCY; "Balance (LCY)") { }
        }
    }

    rendering
    {
        layout(Example_RDLCLayout)
        {
            Type = RDLC;
            LayoutFile = './src/Reports/Example_RDLCLayout.rdl';
            Caption = 'Example_RDLCLayout';
            Summary = 'An example of an RDLC Layout.';
        }
    }
}

To enable multiple layouts, you must use the rendering section of a report object. Inside the rendering section, you define one or more layout sections. In each of the layout sections, you specify details about the layout file path and name, you provide a Caption property and a Summary property which will be displayed to the user in the Report Layouts page in Business Central.

If you don't specify a caption, the layout name will be displayed to the user. The default layout can be specified with the DefaultRenderingLayout property report property. This property can't be set on report extension objects, only on report objects.

Reports using the previous property-based layout specification can be converted to use the rendering section by using a code action. To use this, ensure code that actions are switched on in your AL extension settings and place the cursor on any of the old layout properties to use the action. Layouts of type RDLC, Word, Excel, and Custom can be specified with the new rendering syntax.

You can change a report to use another layout from the Dynamics 365 Business Central client.

To generate the layout, build the extension (Ctrl+Shift+B). The Example_RDLCLayout.rdl file will be created in the current project folder.

If the report layout isn't generated, open the settings.json from Visual Studio Code. Use Ctrl+Shift+P, then select Preferences:, Open User Settings, and locate the AL Language extension. Under Compilation Options, choose Edit in settings.json and add the following line:

"al.compilationOptions": {
   "generateReportLayout": true
} 

To generate the layout, build the extension (Ctrl+Shift+B). The Example_RDLCLayout.rdl file will be created in the root of the current project.

To open the generated report layout file, in Microsoft SQL Server Report Builder, right-click the Example_RDLCLayout.rdl file and then select the Open Externally option, as shown in the following screenshot.

Screenshot example of the RDLC Layout menu.

You can now edit the layout in Microsoft SQL Server Report Builder. Alternatively, you can also select to edit the report layout with Microsoft Visual Studio Report Designer.

You can give the layout file the extension .rdl or .rdlc. So you can select to either use Example_RDLCLayout.rdl or Example_RDLCLayout.rdlc. Usually by default an .rdl file opens with Microsoft SQL Server Report Builder and an .rdlc file opens with Microsoft Visual Studio Report Designer. By changing the .rdl to .rdlc or .rdlc to .rdl you determine which tool is used when using the Open Externally command in Visual Studio Code.

Screenshot of the Report Builder layout window.

In Microsoft SQL Server Report Builder, you can view the dataset under Report Data in the Datasets folder. The name of the dataset for Business Central reports is always DataSet_Result.

You can view the available fields in the dataset. The names of the fields in the dataset in the layout are the same as the corresponding field names in the report dataset in the .al file in Visual Studio Code.

Now, you can add a table to the report layout. Right-click the report body and select Insert > Table.

Screenshot of the layout window menu to add table.

Then, add fields from the dataset onto the table, as shown in the following screenshot.

Screenshot of the layout window to add fields.

After you have added fields to the table, you can format by selecting rows, fields, or columns and by using the formatting buttons in the ribbon. In the preceding example, the header row has been formatted with bold font.

Next, save and close Microsoft SQL Server Report Builder.

In Visual Studio Code, press the Ctrl+F5 keyboard shortcut to compile and run the report in Dynamics 365 Business Central. In Business Central, use the Tell Me button to search for the report and run it.

The generated report will be shown in preview mode.

Screenshot of the layout of the report in preview mode.

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.