Edit

Share via


OnGetFilename event

This article describes the syntax of the OnGetFilename event and the attributes of the report payload.

Usage

The OnGetFilename event lets you set the filename that's suggested or used when you export a report, like to PDF, Excel, or Word. Subscribe to this event to use your own logic for naming exported report files, like adding the date, customer name, or other details, instead of the default filename.

Use this event to:

  • Make filenames more descriptive or user friendly.
  • Meet business or compliance requirements for file naming.
  • Avoid filename conflicts when you export multiple reports.

Publisher

Codeunit 44 ReportManagement.

Raised

When the user selects Print, Preview, or one of the Send to actions except Schedule on a report request page.

Event signature

[IntegrationEvent(false, false)]
local procedure OnGetFilename(ReportID: Integer; Caption: Text[250]; ObjectPayload: JsonObject; FileExtension: Text[30]; ReportRecordRef: RecordRef; var Filename: Text; var Success: Boolean)

Event subscriber syntax

[IntegrationEvent(false, false)]
local procedure OnGetFilename(ReportID: Integer; Caption: Text[250]; ObjectPayload: JsonObject; FileExtension: Text[30]; ReportRecordRef: RecordRef; var Filename: Text; var Success: Boolean)

Parameters

ReportID

Type: Integer

The ID of the report object.

ObjectPayload

Type: JsonObject

Instance of the report payload. Learn more in Report payload structure.

FileExtension

Type: Text

Specifies the file extension of the saved report, like .pdf, .docx, or .xlsx.

Success

Type: Boolean

Specifies whether the extension handled the action successfully.

Report payload

The report payload contains metadata for the report object and a list of attributes that identifies that current invocation. The payload consists of several attributes and has the following structure.

{
    "filterviews":
    [
        {"name":"Header","tableid":112,"view":"VERSION(1) SORTING(Field3) WHERE(Field3=1(103027))"},
        {"name":"Line","tableid":113,"view":"VERSION(1) SORTING(Field3,Field4) WHERE(Field4=1(0..10000))"},
        {"name":"ShipmentLine","tableid":7190,"view":"VERSION(1) SORTING(Field1,Field2,Field3) WHERE(Field2=1(10000))"}
    ],
    "version":1,
    "objectname":"Standard Sales - Invoice",
    "objectid":1306,
    "documenttype":"application/pdf",
    "invokedby":"00000000-0000-0000-0000-000000000001",
    "invokeddatetime":"2020-01-17T15:33:52.48+01:00",
    "companyname":"CRONUS International Ltd.",
    "printername":"My Printer",
    "duplex":false,
    "color":false,
    "defaultcopies":1,
    "papertray":
    {
        "papersourcekind":257,
        "paperkind":0,
        "landscape":false,
        "units":0,
        "height":1268,
        "width":929
    },
    "intent":"Print",
    "layoutmodel": "Rdlc",
    "layoutname": "RDLCLayout",
    "layoutmimetype": "Application/ReportLayout/Rdlc",
    "layoutapplicationid": "00001111-aaaa-2222-bbbb-3333cccc4444",
    "reportrunid": "6a3742c1-65ef-44a6-af58-3ef4a902932b"
}

Attributes

objectname

Specifies the name of the object.

objectid

Specifies the ID of the object.

documenttype

Specifies the MIME type of the document. Currently only application/pdf is supported for printing, other intents can have types specific to the report layout model and selected output target type.

invokedby

Specifies the ID of the user who invoked the print action.

invokeddatetime

Specifies the date and time that the print action was invoked, for example, 2019-10-22T22:25:54.338+02:00. The value is the date and time on the client machine.

companyname

Specifies the Business Central company.

version

Specifies the version of the report payload. Currently, the only supported version for the payload is 1.

duplex

Specifies whether to use duplex (2-sided) printing. true specifies duplex printing; otherwise false.

Note

duplex is currently not used and ignored at runtime.

color

Specifies whether color printing is set. true specifies color printing; otherwise false.

Note

color is currently not used and ignored at runtime.

defaultcopies

Specifies the number of copies to print by default. The default is 1.

Note

defaultcopies is currently not used and ignored at runtime.

filterviews

Specifies views that are used on the document.

name

Specifies the name of data item that the filter view applies to.

tableid

Specifies the ID of the table for the view.

view

Specifies the name of the view.

papertray

Specifies the paper tray settings from the printer payload.

papersourcekind

Specifies a standard paper source for the paper tray. The value can be either the text representation (such as AutomaticFeed) or the corresponding number (such as 7).

paperkind

Specifies the paper size. The value can be either the text representation (such as A4) or the corresponding number (such as 9).

landscape

Specifies whether landscape orientation is used. true specifies landscape orientation; otherwise false.

units

Specifies the units of measurement for values in height and width attributes. Valid values include:

  • HI for hundredths of an inch (default value).
  • TI for thousandths of an inch.
  • IN for inches.
  • CM for centimeters.
  • MM for millimeters.
  • PC for picas.
  • PT for points.

height

Specifies the height of the paper. The values include positive integers up to 2,147,483,647.

width

Specifies the width of the paper. The values include positive integers up to 2,147,483,647.

intent

Specifies the intent of the current report invocation, which can be one of the following values.

  • None
  • Print
  • Preview
  • Save
  • Schedule
  • Download
  • Parameters

layoutmodel

Specifies the layout model selected for teh current report invocation, which can be one of the following values.

  • Rdlc
  • Word
  • Excel
  • Custom

layoutname

Specifies the layout name for the currently selected layout.

layoutmimetype

Specifies the layout mimetype for the currently selected layout. The built-in layout types are:

  • Application/ReportLayout/Rdlc
  • Application/ReportLayout/Word
  • Application/ReportLayout/Excel

layoutapplicationid

Specifies the ID of the application that provides the selected layout.

reportrunid

Specifies a unique ID of type Guid that identifies the current report invocation. This value can be used to correlate calls to report event that support json payloads.

Example

This AL code subscribes to the OnGetFilename event to customize the filename with the current date when you save a report as a PDF.

codeunit 50100 MyFilenameSubscriber
{
    [EventSubscriber(ObjectType::Codeunit, Codeunit::ReportManagement, 'OnGetFilename', '', false, false)]
    local procedure OnGetFilenameHandler(ReportID: Integer; Caption: Text[250]; ObjectPayload: JsonObject; FileExtension: Text[30]; ReportRecordRef: RecordRef; var filename: Text; var Success: Boolean)
    begin
        // Check if this is the "Customer - Top 10 List" report and PDF export
        if (FileExtension = '.pdf') then begin
            Filename := Caption + '_' + Format(Today, 0, '<Year>-<Month>-<Day>');
            Success := true; // Mark as handled to prevent the default filename logic

        end;
    end;
}

Tip

For a more complex example of how to use this event, see codeunit 1890 "Reminder Communication" in the Business Central base application.

Working With and Troubleshooting Payloads
Developing Printer Extensions Overview
Creating a Printer Extension
Events in AL
Publishing Events
Raising Events
Subscribing to Events