Exercise - Create a basic report

Completed

This exercise uses the CRONUS sample company from the US version of Business Central. You might need to adjust the steps if you use the sample company from your country or region.

Scenario

You are a developer working for CRONUS. You have been asked to create a report to list all customers. This report needs to have an RDLC, a Word, and an Excel layout.

Create a report that has the following requirements:

  • Prints all customers.

  • Creates the RDLC report layout.

  • Creates the Word report layout.

  • Creates the Excel layout.

Tasks

  • Create the page extension.

  • Create the dataset.

  • Create an RDLC layout for the report.

  • Create a Word layout for the report.

  • Create an Excel layout for the report.

Steps

Create the page extension for the Customer List.

  1. In Visual Studio Code, add a new file with the name CustomerList.PageExt.al.

  2. Create an extension for the Customer List by using the following code:

pageextension 50123 CustomerList extends "Customer List"
{
    trigger OnOpenPage();
    begin
        report.Run(Report::LABCustomerList);
    end
}

Create the dataset.

  1. In Visual Studio Code, add a new file with the name LABCustomerList.Report.al.

  2. Create the dataset for the report by using the following code:

    report 50102 LABCustomerList
    {
    Caption = 'LAB CustomerList';
    ApplicationArea = All;
    UsageCategory = ReportsAndAnalysis;
    PreviewMode = Normal;
    DefaultRenderingLayout = Example_EXCELLayout;
    
    dataset
    {
        dataitem(Customer; Customer)
        {
            DataItemTableView = sorting(Name);
    
            column(No; "No.")
            {
                IncludeCaption = true;
            }
            column(Name; Name)
            {
                IncludeCaption = true;
            }
            column(Balance; "Balance (LCY)")
            {
                IncludeCaption = true;
            }
        }
    }
    rendering
    {
        layout(Example_RDLCLayout)
        {
            Type = RDLC;
            LayoutFile = './src/Reports/LABS/layouts/LABCustomerList.rdl';
            Caption = 'LABCustomerList';
            Summary = 'An example of an RDLC Layout.';
        }
        layout(Example_WORDLayout)
        {
            Type = Word;
            LayoutFile = './src/Reports/LABS/layouts/Example_WORDLayout.docx';
            Caption = 'LABCustomerList';
            Summary = 'An example of an WORD Layout.';
        }
        layout(Example_EXCELLayout)
        {
            Type = Excel;
            LayoutFile = './src/Reports/LABS/layouts/Example_EXCELLayout.xlsx';
            Caption = 'LABCustomerList';
            Summary = 'An example of an Excel Layout.';
        }
    }
    
  3. Add a subfolder named layouts in the project.

  4. Build the report by using the Ctrl+Shift+B keyboard shortcut, which will generate the RDLC and Word layouts.

    Screenshot of the layouts drop-down menu.

Create an RDLC layout for the report.

  1. Right-click the LABCustomerList.rdl file and then select Open Externally.

    Report Builder should open.

    Screenshot of the LAB_CustomerList.rdl file opened in Report Builder.

  2. In the Insert menu, select Table > Table Wizard.

    Screenshot of the Table Wizard menu item.

  3. In the New Table or Matrix window, select DataSet_Result and then select Next.

  4. Drag the No, Name, and Balance fields onto the Values section.

    Screenshot of the New Table or Matrix window values section.

  5. Select Next.

  6. Select Next.

  7. Select Finish.

  8. Select the Name column and make it wider.

  9. Select the first row and then align the content to the left.

    Screenshot of the content alighed to the left.

  10. Save and Close Report Builder.

Create a Word layout for the report.

  1. Right-click the LAB_CustomerList.docx file and then select Open Externally.

    Microsoft Word will open.

  2. Create a table in Word with two rows and three columns.

    1. On the Insert tab, select Table.

    2. Select two rows and three columns.

      Screenshot of the insert table rows and columns selector.

  3. In the ribbon, right-click and select Customize the Ribbon.

    1. In the column on the right, enable Developer.

    2. Select OK.

  4. On the Developer tab in the ribbon, select XML Mapping Pane.

  5. On Custom XML Part, select urn:microsoft-dynamics-nav/reports/LABCustomerList/50102/.

  6. Expand Customer.

  7. On the first row, enter No, Name, and Balance in the first, second, and third columns, respectively.

    Screenshot of the column headers visual example.

  8. Select the second row.

  9. In the XML Mapping pane to the right, right-click Customer and then select Insert Content Control > Repeating.

    Screenshot of the XML Mapping pane details.

  10. In each column of the second row of the table, right-click the Customer field and select Insert Content Control > Plain Text to set the following DataSet Result fields:

    • No

    • Name

    • Balance

    Screenshot of the second row of the table.

  11. Close the Word document and select Save.

Create an Excel layout for the report.

  1. Right-click the Example_EXCELLayout.xlsx file and then select Open Externally.

  2. Microsoft Excel will open. In Excel, click Insert, PivotTable, From Table/Range.

  3. If not present, enter Data in the Table/Range:

    Screenshot of the PivotTable from table or range page.

  4. In the PivotTable Fields, add Name and Customer.

    Screenshot of the PivotTable fields to add to a report.

  5. Close and Save the Excel file.