Business Central 2025 wave 1 (BC26): New report method Report.TargetFormat (Limit the file format/type of report output)

Dynamics 365 Business Central

Hi, Readers.
Dynamics 365 Business Central 2025 wave 1 (BC26) is generally available. More details: General Available: Dynamics 365 Business Central 2025 release wave 1 (BC26).

I will continue to test and share some new features that I hope will be helpful. In this post, I would like to talk about new report method Report.TargetFormat.

This new feature is not yet documented in the Business Central 2025 release wave 1 (BC26) release plan but is mentioned in AL Language extension changelog Version 15.0

Reporting:
Add a new report property TargetFormat that gets the current output format.

https://marketplace.visualstudio.com/items/ms-dynamics-smb.al/changelog

In Business Central, you can save a report to a PDF document, Microsoft Word document, Microsoft Excel workbook, or XML document by choosing Send to, then making your selection. A file is downloaded to your computer.

The file types that can be selected will differ depending on the layout type.

PS: If your organization configured OneDrive for system features, instead of being downloaded, Excel workbooks and Word documents are opened in your browser using either Excel or Word for the web. More details: Dynamics 365 Business Central: How to use Edit in Excel in the browser/web (Excel Online)

With this wave (BC26), Microsoft added a new report method Report.TargetFormat() Method.
Report.TargetFormat() Method: Gets the current report’s target format. (VersionAvailable or changed with runtime version 15.0.)

This method can be invoked using property access syntax.

Let’s look at a simple example. Displays file format before the standard report 1305 “Standard Sales – Order Conf.” output.

For example,

Test video:

  • PDF Document: Pdf
  • XML Document: Xml
  • Microsoft Word Document: Word
  • Microsoft Excel Document (data and layout): Excel
  • Microsoft Excel Document (data only): ExcelDataset

So we can use this new property to control the formats in which users are allowed to export data. Let’s look at another simple example. Prohibit users from exporting to PDF and Excel formats:

Test video:

Test code:

reportextension 50112 MyExtension extends "Standard Sales - Order Conf."
{
    trigger OnPreReport()
    begin
        if CurrReport.TargetFormat in [ReportFormat::Pdf, ReportFormat::Excel] then
            Error('This report cannot be exported in PDF or Excel format.');
    end;
}

PS: In BC25.5 and previous versions

‘CurrReport “Standard Sales – Order Conf.”‘ does not contain a definition for ‘TargetFormat’ AL AL0132

Great. Give it a try!!!😁

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL