Report.SaveAs(Integer, Text, ReportFormat, var OutStream [, RecordRef]) Method

Version: Available or changed with runtime version 1.0.

Runs a specific report without a request page and saves the report as a PDF, Excel, Word, HTML, or XML file. Instead of using the request page to obtain parameters at runtime, the method gets the parameter values as an input parameter string, typically from the return value of a RunRequestPage method call.

Syntax

[Ok := ]  Report.SaveAs(Number: Integer, Parameters: Text, Format: ReportFormat, var OutStream: OutStream [, RecordRef: RecordRef])

Parameters

Number
 Type: Integer
The ID of the report that you want to save. If the report that you specify does not exist, then a run-time error occurs.

Parameters
 Type: Text
A string of request page parameters as XML to use to run the report. The parameter string is retrieved from the return value a RunRequestPage method call.

Format
 Type: ReportFormat
The type of file to save the report as. The following options are supported: Pdf, Excel, Word, and XML.

OutStream
 Type: OutStream
The stream to which to write a report.

[Optional] RecordRef
 Type: RecordRef
The RecordRef that refers to the table in which you want to find a record.

Return Value

[Optional] Ok
 Type: Boolean
true if the operation was successful; otherwise false. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.

Remarks

You typically use this method together with the RunRequestPage Method method. The RunRequestPage method runs a report request page without actually running the report, but instead, it returns the parameters that are set on the request page as a string. You can then call the SaveAs method to get the parameter string and save the report to a file of the specified format.

For a simple example that illustrates how to use the SaveAs method, see the example in the RunRequestPage Method method article.

Note

By default, when a report uses an RDL report layout at runtime, fonts are embedded in the generated PDF. You can specify whether fonts are embedded in the PDF for RDL reports by changing the Report PDF Font Embedding setting in the Dynamics 365 Business Central service instance configuration or changing the PDFFontEmbedding property in report objects.

Error conditions

The method can fail in the following two ways:

  • If no report exists with an object id as specified in "Number".
  • If the string of request page parameters as XML specified in "Parameters" can't be parsed as valid request page data.

If the report you specify doesn't exist, then a runtime error occurs.

Example (robust coding)

This example shows how to use the static SaveAs method in a safe way (where no errors occur).

var
    RequestPageParameters: Text;
    Format: ReportFormat;
    Stream: OutStream;
begin
    // setup RequestPageParameters, Format, and Stream variables

    // Note that by using the scope operator (::), you catch at compile time if MyReport does not exist
    Report.SaveAs(Report::MyReport, RequestPageParameters, Format, Stream);
end;

Report Data Type
Get Started with AL
Developing Extensions