Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article describes the syntax of the OnCustomDocumentMerger event, which will enable use of custom renders given a dataset and a layout. The layout must be specified as a Custom Layout in the rendering section within the report definition.
Remarks
This event has been superseded by a newer event that also passes the report JSON payload in the parameter list. For more information, see OnCustomDocumentMergerEx Event.
Usage
Use the OnCustomDocumentMerger event to specify what happens when the user has specified a custom report layout type that is to be rendered into an artifact in application code. For more information about subscribing to this event, see Developing Report Custom Render Extensions Overview.
Publisher
Codeunit 44 ReportManagement.
Raised
When a user runs a report that uses a custom layout format handled by application code (extension).
Syntax
[IntegrationEvent(false, false)]
local procedure OnCustomDocumentMerger(ObjectID: Integer; ReportAction: Option SaveAsPdf,SaveAsWord,SaveAsExcel,Preview,Print,SaveAsHtml; XmlData: InStream; LayoutData: InStream; var targetDocumentStream: OutStream; var IsHandled: Boolean)
Parameters
ObjectID
Type: Integer
The ID of the report object to be run.
ReportAction
Type: [Option]
Specifies the action to take in the custom document merge process.
Valid values include:
SaveAsPdfGenerates a PDF document in the target stream.SaveAsWordGenerates a Microsoft Word document in the target stream.SaveAsExcelGenerates a Microsoft Excel document in the target stream.SaveAsHtmlGenerates an HTML document in the target stream.PreviewGenerates a PDF document in the target stream, which the platform downloads to the client for preview.PrintGenerates a PDF document in the target stream, which the platform prints using the printer specified for the present report ID.
XmlData
Type: InStream
A stream object that contains the XML dataset generated by the platform runtime. This stream contains the input data for the rendering process.
LayoutData
Type: InStream
A stream object that contains the report layout to be used in the rendering process. The platform provides this data from the standard report layout selection logic and it contains the currently selected layout.
Success
Type: Boolean
Specifies whether the extension handled the merge action successfully.
Note
The platform will handle further processing of the result stream and the extension code must return the rendered artifact in the target stream. The platform will handle:
- Saving to a specified file in save-as scenarios
- Saving to a given stream
- Download to the client
- Print or preview
Sample code
The simplest possible custom document render can be implemented like the following sample that will use the existing application logic to render XML datasets into Microsoft Word or Pdf documents using a given template (Word template).
[EventSubscriber(ObjectType::Codeunit, Codeunit::ReportManagement, 'OnCustomDocumentMerger', '', true, true)]
local procedure OnCustomDocumentMerger(ObjectID: Integer; ReportAction: Option SaveAsPdf,SaveAsWord,SaveAsExcel,Preview,Print,SaveAsHtml; XmlData: InStream; LayoutData: InStream; var printDocumentStream: OutStream; var IsHandled: Boolean)
var
DocumentReportMgt: Codeunit "Document Report Mgt.";
TempBlob: Codeunit "Temp Blob";
DataInStream: InStream;
DataOutStream: OutStream;
begin
if IsHandled then
exit;
TempBlob.CreateOutStream(DataOutStream);
// The supported actions
case ReportAction of
ReportAction::SaveAsPdf, ReportAction::Preview, ReportAction::Print:
begin
// Try to merge the xml data with the layyout and create a stream with the resulting Word document.
if not DocumentReportMgt.TryXmlMergeWordDocument(LayoutData, XmlData, DataOutStream) then
error('Unable to handle custom document merge');
// Convert the Word document to a PDF document using the streams in the blob object.
DocumentReportMgt.ConvertWordToPdf(TempBlob, ObjectID);
TempBlob.CreateInStream(DataInStream);
// Return the stream data to the printDocumentStream for further processing in the server.
CopyStream(printDocumentStream, DataInStream);
IsHandled := true;
end;
ReportAction::SaveAsHtml:
begin
if not DocumentReportMgt.TryXmlMergeWordDocument(LayoutData, XmlData, DataOutStream) then
error('Unable to handle custom document merge');
DocumentReportMgt.ConvertWordToHtml(TempBlob);
TempBlob.CreateInStream(DataInStream);
CopyStream(printDocumentStream, DataInStream);
IsHandled := true;
end;
ReportAction::SaveAsWord:
begin
if not DocumentReportMgt.TryXmlMergeWordDocument(LayoutData, XmlData, printDocumentStream) then
error('Unable to handle custom document merge');
IsHandled := true;
end;
else
error('Unsupported report action %0', ReportAction);
end;
end;
Related information
Working With and Troubleshooting Payloads Developing Report Custom Render Extensions Overview Developing Printer Extensions Overview Creating a Printer Extension Events in AL Publishing Events Raising Events Subscribing to Events