Exercise - Build and extend a report solution

Completed

In this exercise, you create a self-contained customer balance report and a report extension in an existing AL project. You publish the app to a Business Central online sandbox and record evidence that the dataset, request page, translation, layouts, and extension work together.

Prepare the AL project

Use a sandbox company that contains customer records. In Visual Studio Code, open an AL project that connects to the sandbox, and confirm that its app.json ID range includes 70400 through 70499.

  1. In app.json, add TranslationFile to the features array. Keep any existing feature entries.

    "features": [
      "TranslationFile"
    ],
    "idRanges": [
      {
        "from": 70400,
        "to": 70499
      }
    ]
    
  2. In the Visual Studio Code user or workspace settings.json, enable report layout generation.

    "al.compilationOptions": {
      "generateReportLayout": true
    }
    
  3. Create CustomerBalanceReview.Report.al, and paste the following report.

    report 70400 "Customer Balance Review"
    {
        AllowScheduling = true;
        ApplicationArea = All;
        Caption = 'Customer balance review';
        DefaultRenderingLayout = CustomerWord;
        UsageCategory = ReportsAndAnalysis;
    
        dataset
        {
            dataitem(Customer; Customer)
            {
                RequestFilterFields = "No.", City, "Country/Region Code", "Salesperson Code";
    
                column(ReportTitle; ReportTitleLbl) { }
                column(CustomerNo; "No.") { }
                column(CustomerName; Name) { }
                column(CustomerCity; City) { }
                column(CountryRegionCode; "Country/Region Code") { }
                column(SalespersonCode; "Salesperson Code") { }
                column(BalanceLCY; "Balance (LCY)") { }
                column(FormattedBalance; Format("Balance (LCY)")) { }
                column(MinimumBalanceValue; MinimumBalance) { }
    
                trigger OnPreDataItem()
                begin
                    SetFilter("Balance (LCY)", '>=%1', MinimumBalance);
                end;
    
                trigger OnAfterGetRecord()
                begin
                    CalcFields("Balance (LCY)");
                end;
            }
        }
    
        requestpage
        {
            SaveValues = true;
    
            layout
            {
                area(Content)
                {
                    group(Options)
                    {
                        Caption = 'Options';
    
                        field(MinimumBalance; MinimumBalance)
                        {
                            ApplicationArea = All;
                            Caption = 'Minimum balance';
                            ToolTip = 'Specifies the minimum customer balance to include.';
    
                            trigger OnValidate()
                            begin
                                ValidateMinimumBalance();
                            end;
                        }
                    }
                }
            }
        }
    
        rendering
        {
            layout(CustomerWord)
            {
                Type = Word;
                LayoutFile = 'CustomerBalanceReview.docx';
                Caption = 'Customer balance document';
                Summary = 'A Word document that lists customer balances.';
            }
        }
    
        trigger OnPreReport()
        begin
            ValidateMinimumBalance();
        end;
    
        local procedure ValidateMinimumBalance()
        begin
            if MinimumBalance < 0 then
                Error(MinimumBalanceErr);
        end;
    
        var
            MinimumBalance: Decimal;
            MinimumBalanceErr: Label 'Minimum balance must be zero or greater.';
            ReportTitleLbl: Label 'Customer balance review',
                Comment = 'Title shown at the top of the customer report';
    }
    
  4. Build the project. Confirm that CustomerBalanceReview.docx and a generated .g.xlf file appear. The first build generates the Word layout, and a later build packages it.

Add a translation and report extension

The generated Word layout contains the custom XML part for the report dataset. You add a small set of content controls so the preview shows the report title and customer data.

  1. Open CustomerBalanceReview.docx in Word. On the Developer tab, open the XML Mapping Pane, and select the custom XML part for report 70400.

  2. Insert ReportTitle as a plain-text content control. Insert a one-row table, add the Customer element as a repeating content control, and map CustomerNo, CustomerName, and BalanceLCY inside that repeating region. Save and close the document.

  3. Copy the generated .g.xlf file in the Translations folder to CustomerBalanceReview.fr-FR.xlf.

  4. In the copied file, set target-language="fr-FR". Find the translation unit for ReportTitleLbl whose source is Customer balance review, add the following target beside its source, and save the file.

    <target state="translated">Revue du solde client</target>
    
  5. Create CustomerBalanceReviewExt.ReportExt.al, and paste the following report extension.

    reportextension 70401 "Customer Balance Review Ext" extends "Customer Balance Review"
    {
        dataset
        {
            add(Customer)
            {
                column(ExtensionNote; GetExtensionNote()) { }
            }
        }
    
        requestpage
        {
            layout
            {
                addlast(Options)
                {
                    field(IncludeExtensionNote; IncludeExtensionNote)
                    {
                        ApplicationArea = All;
                        Caption = 'Include extension note';
                        ToolTip = 'Specifies whether the extension note is available in the extended dataset.';
                    }
                }
            }
        }
    
        rendering
        {
            layout(CustomerWordExtended)
            {
                Type = Word;
                LayoutFile = 'CustomerBalanceReviewExtended.docx';
                Caption = 'Extended customer balance document';
                Summary = 'A Word layout supplied by the report extension.';
            }
        }
    
        local procedure GetExtensionNote(): Text
        begin
            if IncludeExtensionNote then
                exit(ExtensionNoteLbl);
    
            exit('');
        end;
    
        var
            IncludeExtensionNote: Boolean;
            ExtensionNoteLbl: Label 'Extended customer balance report';
    }
    
  6. Build the project to generate CustomerBalanceReviewExtended.docx. Open the generated file in Word, map the same base fields, and add ExtensionNote as a plain-text content control inside the repeating customer region. Save and close the file, then build again to package both layouts and the translation. Resolve any compiler issue before you publish.

Publish and validate the report

Publish the app to the sandbox, and run Customer Balance Review from Tell Me. Use the following checks to create a short validation record.

  1. Enter -1 for Minimum balance. Record that validation blocks the run. Then enter 0 or another valid value.
  2. Set a City, Country/Region Code, or Salesperson Code filter that matches known customers. Preview the report, return to the open request page, adjust the filter, and preview again.
  3. On the request page, select Send to > Microsoft Excel Document (data only). Confirm that the output includes the expected Customer fields, BalanceLCY, FormattedBalance, MinimumBalanceValue, and ExtensionNote.
  4. Close and reopen the report. Confirm that the saved filter and minimum balance behavior match the values from the previous run.
  5. On the Report Layouts page, find report 70400. Confirm that Extended customer balance document is available. Select it as the active layout because deployment doesn't select a report-extension layout automatically, then run the report again.
  6. Change the user or report language to French if that language is available in the sandbox. Confirm that the translated report title appears. Otherwise, record that the French XLIFF target is packaged and note that runtime language validation requires an enabled French language.
  7. Record the customer filters, minimum balance, returned record count, data-only columns, selected layout, translation result, and any troubleshooting action.

Remove the published development extension from the sandbox when you finish. Keep the source files and validation record if they form part of your development evidence.