Blog
Blog

Customizing Reports in Business Central: Adding New Fields and Date Filters to the Production Order Statistics Report

Posted on 04-Mar-2025 by Islam Shaikh Technical Consultant

Extending a Standard Report in Business Central

In Business Central, extending a standard report allows us to add custom fields, incorporate additional logic, and enhance report functionality without modifying the base application. In this blog, I will walk you through how I extended the Production Order Statistics report to include additional fields and apply a date filter.

Step 1: Creating the Report Extension

We begin by extending the standard Production Order Statistics report using the treportext snippet. In our case, we name the layout file Prod Order Statistics LFS.rdl, as shown in the image.

Creating a report extension in Visual Studio Code for the Production Order Statistics report.Next, we build the package by pressing Ctrl + Shift + B. This action generates the layout file (Prod Order Statistics LFS.rdl). If we open this file at this stage, it will be blank.

Building the report extension package in VS Code to generate the new layout file.Step 2: Verifying the Layout in Business Central

After a successful build, we can verify the new layout in Business Central.

Navigate to the Search tab and type "Report Layout".

Searching for Report Layouts in the Dynamics 365 Business Central global search bar.Using the report ID, you will see both the standard layout and the customized layout.

Selecting the customized Production Order Statistics layout from the report layouts list.

Select the customized layout (Prod Order Statistics) and set it as the default.

Setting the new custom report extension layout as the default in Business Central.

Step 3: Importing the Standard Layout

The customized layout, Prod Order Statistics LFS.rdl, is currently blank, we need to populate it by exporting the standard layout:

Export the standard layout from Business Central.

Exporting the standard report layout from Business Central to use as a foundation for customization.Save the exported layout as Prod Order Statistics LFS.rdl in your project folder (where the initial layout was generated).

Saving the exported report layout file into the local project folder for VS Code editing.By doing this, our customized layout will now mirror the standard layout, providing a foundation for our modifications. After saving the file if we check our layout rdl file in VS Code.

Synchronizing the RDLC layout file in Visual Studio Code to reflect dataset changes.The rdl file we open will look exactly same as standard layout where we will do our changes.

Opening the report layout designer to visually map new fields to the report table.

Step 4: Adding New Fields to the Dataset

With the customized layout in place, we can now add new fields and logic.

In Visual Studio Code (VS Code), we add columns for fields we need inside the dataset using the add method. After writing the code, build the package (Ctrl + Shift + B) to reflect these changes in the layout.

Here is a sample syntax for adding a Column:

add('DataItem Name')

Adding new columns to the report dataset using the add() method in AL code.

Viewing the updated dataset fields within the Visual Studio report designer interface.You can write code within the OnAfterGetRecord trigger of the DataItem. To do this, use the modify method and insert your logic inside the OnAfterAfterGetRecord trigger. Store values in variables and add those variables as columns in the layout.

modify(‘DataItem Name’)

Inserting custom logic into the OnAfterGetRecord trigger to calculate report values.Using the modify() method in AL to change existing report dataset behaviors.Defining global variables and calculation logic within the Business Central report extension.Mapping calculated AL variables to the final report layout cells in the designer.

Step 5: Enhancing the Request Page

We can also add fields to the Request Page to allow user input for filtering.

Use the addlast(Content) or addfirst(Content) method to create groups and include fields. In our case, we add StartDate and EndDate fields.

Writing filtering logic in the OnBeforePreDataItem trigger to retrieve data by specific date ranges in AL.To filter the DataItem using the request page fields, write the filtering logic within the OnBeforePreDataItem trigger inside the modify. This ensures the report retrieves data according to the specified date range.

Final AL code block for the Production Order Statistics report extension in Visual Studio Code.Step 6: Testing the Customized Report

Finally, we test the updated report:

In Business Central, search for the Production Order Statistics report.

Searching for the Production Order Statistics report in the Dynamics 365 Business Central search bar.

In request page, we can see Report Layout is getting our custom layout because we have selected this layout as default above, also Start Date and End Date is also gets added in Request Page.

Updated report request page in Business Central featuring new Start Date and End Date filter fields.

Generated report will have our custom values in report.

The final customized Production Order Statistics report in Business Central showing new fields and calculated values.This process allows you to add new fields, adjust data retrieval logic, and personalize request pages while maintaining the integrity of the base application.

Happy coding!


Post a Comment

Your email address will not be published. Required fields are marked (*)

Captcha
can't read? refresh

WhatsApp Now