Creating Report Layouts

Earn 25 points (50 with Pro) in two steps

  1. ① Read through the lesson — each section gets a ✓ as you scroll through it.
  2. ② When every section has a ✓, tap Complete lesson.

0 of 10 read · keep scrolling

✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro

Lesson: Creating Report Layouts in AL

Introduction: The Power of Visual Data Representation

In the ecosystem of Business Central development, the data contained within the database is only as valuable as our ability to present it to the end user. While AL (Application Language) excels at processing business logic, calculating totals, and managing complex data relationships, the final output—the report—is what stakeholders actually see and use to make decisions. Creating report layouts is the bridge between raw data and meaningful business intelligence. Whether you are generating a simple packing slip, a complex financial statement, or an analytical inventory report, the layout defines how that information is consumed.

Understanding how to build and extend these layouts is a fundamental skill for any AL developer. It requires a shift in mindset from pure procedural coding to visual design and data binding. By mastering both the AL data structure and the layout file (typically RDLC or Word), you ensure that your business solutions are not just functional, but professional and user-friendly. This lesson explores the technical architecture of report layouts, the tools required to design them, and the strategies for maintaining them in a modern development environment.

Not read yet

Understanding the Report Architecture

Before diving into the design tools, we must understand the two distinct parts of a report object in AL. Every report is composed of a data set definition and one or more layout files. The data set definition is written in AL code within the report object, while the layout file is an external file that resides in your project folder.

The Data Set Definition (AL)

The data set is the "what" of your report. You define it using the dataset block, where you specify which tables and fields you want to pull from the database. You can also include variables, functions, and calculated fields. The data set acts as a pipeline that feeds information into the layout. If a field is not defined in your AL code, it simply does not exist for the layout designer.

report 50100 "Customer List Report"
{
    UsageCategory = ReportsAndAnalysis;
    ApplicationArea = All;
    Caption = 'Customer List';

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

The Layout File

The layout is the "how" of your report. It determines the font, colors, alignment, grouping, and visual structure of the data provided by the data set. Business Central supports two primary layout formats: RDLC (Report Definition Language Client-side) and Word. RDLC layouts provide high precision and are better suited for complex, multi-page documents, whereas Word layouts offer an easier, template-based approach for users who want to customize documents like invoices or quotes using familiar word processing tools.

Callout: RDLC vs. Word Layouts When deciding between RDLC and Word, consider the complexity of the report. RDLC is a pixel-perfect design environment that allows for complex expressions, conditional visibility, and intricate grouping. Word layouts are ideal for documents where the user might want to adjust the look and feel—like changing a logo or adding a signature line—without needing to open a specialized report designer.

Not read yet

Working with RDLC Layouts

RDLC layouts are the standard for professional reporting in Business Central. They are based on the Microsoft Reporting Services format and are edited using the Visual Studio Report Designer.

Step-by-Step: Creating an RDLC Layout

  1. Define the Report in AL: Create your report object and define the dataset.
  2. Set the Layout Property: Inside your report object, set the RDLCLayout property to the path of your file, for example, RDLCLayout = 'CustomerList.rdl';.
  3. Generate the Layout: Compile your project. If the layout file does not exist, the compiler will create an empty one for you in the specified path.
  4. Open in Designer: Right-click the .rdl file in your Visual Studio Code explorer and select "Open Externally." This will open the file in the Visual Studio Report Designer.
  5. Design the Layout: Use the "Report Data" pane to drag and drop fields from your dataset onto the report body. You can add tables, matrices, and charts to visualize your data.

Best Practices for RDLC

  • Keep Datasets Lean: Only include fields that you strictly need. Large, unnecessary datasets can slow down report rendering significantly.
  • Use Grouping Wisely: Grouping is the engine of RDLC reports. Learn to use the grouping pane to create headers and footers that repeat based on specific data values, such as customer number or date ranges.
  • Conditional Formatting: Use expressions to highlight data. For example, you can set the Color property of a balance field to "Red" if the value is less than zero using an expression like =IIF(Fields!Balance.Value < 0, "Red", "Black").

Tip: Managing Layout Files Always keep your .rdl or .docx files within the same folder structure as your AL files. This ensures that when you commit your code to source control (like Git), the layout is version-controlled alongside the logic. Never rely on manually uploading layouts through the Business Central client for production development.

Not read yet

Working with Word Layouts

Word layouts are incredibly popular because they allow developers to hand off report templates to non-developers. By using a Word document as a template, you can leverage standard formatting tools like headers, footers, tables, and branding elements.

The XML Mapping Pane

The secret to Word layouts is the "XML Mapping Pane." Once you have generated the report in AL, you can open the Word template and use the Developer tab to map specific AL fields to content controls in the document.

  1. Enable Developer Tab: In Word, go to Options > Customize Ribbon and check "Developer."
  2. Open the XML Mapping Pane: Click the "XML Mapping" button in the Developer tab.
  3. Select the Custom XML Part: In the dropdown menu, select the schema that matches your report name.
  4. Insert Controls: Right-click on a field in the tree view and choose "Insert Content Control" to place it in the document.

Common Pitfalls in Word Layouts

  • Table Rows: When you want to repeat data (like a list of lines in an invoice), you must wrap the table row in a "Repeating Content Control." If you don't do this, the report will only display the first record.
  • Formatting Constraints: Word layouts are less flexible than RDLC. You cannot perform complex calculations or advanced conditional logic within the template itself. All logic must reside in the AL code.
  • Image Handling: Inserting images into Word layouts can be tricky. Always ensure the image is properly anchored and set to "In Line with Text" to avoid unexpected layout shifts when the report renders.

Not read yet

Comparison: RDLC vs. Word Layouts

Feature RDLC Layout Word Layout
Complexity High (Supports complex logic) Low (Simple template design)
Tooling Visual Studio Report Designer Microsoft Word
User Customization Difficult for end-users Easy for end-users
Performance High performance Moderate
Best Use Case Financial statements, analytical reports Invoices, quotes, packing slips

Advanced Techniques: Extending Reports

One of the most powerful features in Business Central is the ability to extend existing reports without modifying the base application code. This is done using the reportextension object.

Extending the Data Set

If you need to add a field to a standard report, you don't need to rebuild it from scratch. You can create a reportextension that adds new columns to the existing data item.

reportextension 50101 "MyCustomerReportExt" extends "Standard Customer List"
{
    dataset
    {
        add(Customer)
        {
            column(Customer_Email; "E-Mail") { }
        }
    }
}

Extending the Layout

When you extend a report, you must also update the layout. You can define a new layout property in your extension, or you can add new content to the existing layout file. Note that when you use reportextension, you are essentially adding to the available data pool, and you must manually update the layout file to incorporate these new fields.

Warning: The Extension Trap Be careful when extending standard reports. If you add too many fields or complex logic to a standard report, you may encounter performance issues or conflicts with other extensions. Always verify that your additions are necessary and do not negatively impact the performance of the original report.

Not read yet

Best Practices for Professional Reports

1. Maintain Consistent Branding

Every report should share a common look and feel. Create a standard template for fonts, colors, and logo placement. If your organization has a style guide, ensure your report layouts adhere to it strictly. This makes the system look cohesive and professional.

2. Design for Internationalization

Business Central is a global product. Always design your reports to support multi-language labels. Instead of hardcoding text like "Invoice Number," use labels in your AL code. This allows the system to automatically translate the text based on the user's language settings.

labels
{
    InvoiceNoLabel = 'Invoice No.';
}

3. Test with Varying Data Volumes

A report that looks great with three records might break when it has three thousand. Always test your layouts with a "stress test" dataset. Check how the report handles page breaks, overflow text, and long lists. If you have a table that spans multiple pages, ensure you have set the "Repeat Header on Every Page" property in your RDLC layout.

4. Use Global Variables for Formatting

Sometimes you need to format data based on user preferences, such as date formats or currency symbols. Do not try to handle this inside the layout if it can be avoided. Instead, prepare the data in AL by converting values to strings or using formatting functions like Format(). This keeps your layout logic simple and maintainable.

Not read yet

Common Pitfalls and Troubleshooting

"The Report Layout is Missing"

This error often occurs when the AL compiler cannot find the file specified in the RDLCLayout property. Double-check your path, including the folder structure. Remember that AL is case-sensitive on some operating systems, so ensure the filename matches exactly.

Data Not Showing Up

If you have added a column in AL but it doesn't appear in the report, first check your dataset. Is the column actually being populated? Then, check your layout. Did you add the field to the table? Did you re-import the layout file into the report object? Sometimes, the designer might be pointing to an old version of the dataset. If this happens, try refreshing the data source in your design tool.

Formatting Issues in Word

If a Word layout is not outputting the data as expected, check the XML Mapping pane. Sometimes, fields become unlinked from the data source. Delete the control, re-open the XML mapping pane, and re-insert the field. Also, check for hidden "Section Breaks" in your Word document, as they can sometimes interfere with how the report engine renders the content.

Callout: The Importance of Iteration Report development is rarely a one-shot process. Expect to move back and forth between your AL code and your layout file multiple times. This iterative process is normal. Use the "Preview" function frequently to check your changes without needing to fully deploy the extension to the server.

Not read yet

Step-by-Step: Adding a Logo to a Report

Adding a company logo is one of the most common requests in report development. Here is the standard approach for an RDLC layout:

  1. Add the field to the Dataset: In your AL code, add a column that retrieves the company information, specifically the Picture field from the "Company Information" table.
  2. Add an Image Control: In the RDLC designer, drag an "Image" control onto the report header.
  3. Configure the Image: Right-click the image and select "Image Properties." Set the "Select the image source" to "Database."
  4. Set the MIME Type: Set the MIME type to "image/bmp" or "image/png" depending on your logo file.
  5. Bind the Field: In the "Use this field" dropdown, select the field you added in your dataset (e.g., CompanyInfo_Picture).
  6. Adjust Sizing: Set the "Sizing" property to "FitProportional" so your logo doesn't become distorted if the company image aspect ratio changes.

Not read yet

Industry Standards: When to Move Beyond Built-in Layouts

While RDLC and Word are standard, there are scenarios where they fall short. If you find yourself needing to generate highly complex, interactive, or multi-modal documents, you might consider using an external reporting service or a dedicated document management solution.

However, for 95% of Business Central use cases, mastering the built-in layout tools is sufficient. The key is to leverage the AL code to do the heavy lifting. By performing complex calculations, sorting, and data filtering in AL, you keep your layout file simple, which makes it easier to maintain, debug, and update in the future.

Summary: Key Takeaways for Success

  • Data is King: Always focus on building a clean, efficient dataset in your AL code before worrying about the visual layout.
  • Choose the Right Tool: Use RDLC for complex, pixel-perfect requirements and Word layouts for user-friendly, template-based documents.
  • Version Control: Always store your layout files in your source control system. Treat them with the same care as your AL code.
  • Stay Simple: Avoid putting complex business logic inside the layout file. If a calculation is needed, perform it in AL and pass the result as a variable to the report.
  • Think Globally: Use labels and formatting functions to ensure your reports are ready for international use from day one.
  • Iterate and Test: Use the preview function constantly to verify your changes and ensure your report handles both small and large datasets gracefully.
  • Extend Responsibly: When using reportextension, keep your additions focused and test them thoroughly to avoid performance degradation or conflicts with other extensions.

By following these principles, you will be able to create reports that are not only functional but also a true asset to the businesses you serve. Remember that a great report is one that answers the user's question before they have to ask it, providing clear, accurate, and well-presented data that drives informed decision-making.

Not read yet

FAQ: Frequently Asked Questions

Can I use external fonts in my reports?

Yes, but be aware that the report server must have those fonts installed. If you are using Business Central Online (SaaS), you are limited to the fonts provided in the standard environment. For on-premises installations, you can install custom fonts on the server.

How do I handle page numbers?

In RDLC, you can use the built-in Globals!PageNumber and Globals!TotalPages expressions. In Word, you can use the standard "Insert Page Number" feature in the header or footer, which works correctly with the reporting engine.

Can I share one layout between multiple reports?

No, each report object must have its own layout file. However, you can copy and paste the contents of an RDLC layout file into another, provided the datasets are identical.

Why is my report running slowly?

Slow reports are almost always caused by inefficient AL code in the dataset definition (e.g., poor filtering or excessive table lookups) or by trying to process too much data at once. Always filter your data as much as possible before it reaches the layout.

Is it possible to use JavaScript in reports?

No. Business Central reports do not support client-side scripting or JavaScript. All logic must be handled in AL or via expressions within the RDLC layout engine.

Conclusion

Creating report layouts is an essential part of the Business Central developer's toolkit. By understanding the relationship between the AL data set and the visual layout, you gain the ability to turn abstract data into clear, actionable information. Whether you choose the power of RDLC or the simplicity of Word, the core principles of lean data design, consistent branding, and iterative testing remain the same. As you continue your development journey, use these tools to create reports that are intuitive, professional, and built for the long term.

Not read yet

Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.