With the release of Microsoft Dynamics 365 Business Central 2025 Wave 1, Microsoft has continued to improve the AL language and reporting capabilities. One notable addition for developers working with reports is the new Report.TargetFormat()
method. This small yet powerful enhancement gives developers more control and visibility over how reports are executed, especially in scenarios involving automation, scheduling, or integration.
The Report.TargetFormat()
method allows you to set the target output format for a report at runtime. This is particularly useful in scenarios where the desired output format isn’t static or needs to be determined based on user preferences, system configurations, or specific business logic.
Imagine you have a page action that allows users to export a list of customers. Instead of having separate actions for different formats, you can use Report.TargetFormat()
to dynamically generate the output in Excel.
pageextension 50100 CustomerListExt extends "Customer List"
{
actions
{
addfirst(Processing)
{
action(ExportToExcel)
{
Caption = 'Export to Excel';
Image = ExportExcel;
trigger OnAction()
var
CustomerListReport: Report "Customer List";
ReportSettings: Record "Report Settings";
begin
ReportSettings.TargetFormat := Enum::"Report Format"::Excel;
CustomerListReport.Run(ReportSettings);
end;
}
}
}
}
In this example, before running the “Customer List” report, we set the TargetFormat
property of a ReportSettings
record to Excel
. When the report is executed using Run(ReportSettings)
, it will automatically be generated as an Excel file.
Consider a scenario where you need to automatically generate and archive a sales order confirmation as a PDF after the order is posted. You can achieve this within a codeunit.
codeunit 50101 SalesOrderProcessing
{
procedure GenerateConfirmationPDF(SalesHeaderRec: Record "Sales Header")
var
SalesConfirmationReport: Report "Sales - Order Conf.";
ReportSettings: Record "Report Settings";
begin
ReportSettings.TargetFormat := Enum::"Report Format"::PDF;
SalesConfirmationReport.SetTableView(SalesHeaderRec);
SalesConfirmationReport.Run(ReportSettings);
// Code to archive the generated PDF can be added here
end;
}
Here, within the GenerateConfirmationPDF
procedure, we explicitly set the TargetFormat
to PDF
for the “Sales – Order Conf.” report. When the report is run, it will be generated directly as a PDF document.
You can create a more user-friendly experience by presenting users with a choice of output formats before running a report.
pageextension 50102 ItemListExt extends "Item List"
{
actions
{
addfirst(Processing)
{
action(ExportItemData)
{
Caption = 'Export Item Data';
Image = Export;
trigger OnAction()
var
ItemListReport: Report "Item List";
ReportSettings: Record "Report Settings";
ExportFormat: Option "PDF","Excel","CSV";
begin
ExportFormat := Dialog.Confirm('Choose Export Format:', true, ExportFormat);
case ExportFormat of
ExportFormat::PDF:
ReportSettings.TargetFormat := Enum::"Report Format"::PDF;
ExportFormat::Excel:
ReportSettings.TargetFormat := Enum::"Report Format"::Excel;
ExportFormat::CSV:
ReportSettings.TargetFormat := Enum::"Report Format"::CSV;
end;
ItemListReport.Run(ReportSettings);
end;
}
}
}
}
The Report.TargetFormat()
method is a subtle yet powerful addition to the AL reporting toolbox in Business Central 2025 Wave 1. It unlocks a new level of flexibility for report behavior and presentation, enabling developers to create more intelligent, format-aware reporting solutions.
Stay tuned for more.
Original Post https://ammolhsaallvi.blog/2025/04/21/report-targetformat-method-in-business-central-2025-wave-1/