Editar

Compartir vía


Report.SaveAsXml(Integer, Text [, var Record]) Method

Version: Available or changed with runtime version 1.0.

Saves the resulting data set of a query as an .xml file. The following code shows the syntax of the SaveAsXml method. The first line of code is the syntax for an instance method call. The second line of code is the syntax for a static method call.

Note

This method is supported only in Business Central on-premises.

Syntax

[Ok := ]  Report.SaveAsXml(Number: Integer, FileName: Text [, var Record: Record])

Parameters

Number
 Type: Integer
The ID of the query object that you want to save as an .xml file. If the query that you specify does not exist, then a run-time error occurs.

FileName
 Type: Text
The path and name of the file that you want to save the query to.

[Optional] Record
 Type: Record
Specifies which record to use in the report. Any filters that have been applied to the record that you specify will be used.

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 can use the SaveAsXml method on the global Report object and on instances of a Report variable. If, at design time, you do not know the specific report that you want to run, then use this method (the static one) and specify the report object ID in the Number parameter. If you do know which report you want to run, then use the instance method Report.SaveAsXml(FileName: Text).

When you call the SaveAsXML method, the report is generated and saved to the file specified in "FileName." The request page is not shown.

Error conditions

The method can fail in the following four ways:

  • If no report exists with an object id as specified in "Number".
  • If the destination folder specified in FileName does not exist,
  • If the file specified in FileName is being used, or
  • If the Business Central server process does not have permission to write to the file specified in FileName.

If the report you specify does not exist, then a run-time error occurs.

If the destination folder that you specify in FileName does not exist, then you get the following error: The specified path is invalid.

If the file that you specify in FileName is being used, then you get the following error: An I/O exception occurred during the operation.

If the Business Central server process does not have permission to write to the file that you specify in FileName, then you get the following error: Either the caller does not have the required permission or the specified path is read-only.

Note

The FileName parameter specifies a location on the computer that is running Business Central. If you call this method from a client, such as from an action on a page, then use the File.Download method to download the .pdf file from the computer that is running the Business Central server to the computer that is running the client.

Example

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

var
    FileNameAndPath: Text[250];
begin
    // setup that FileNameAndPath is valid to write to

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

For a full example that shows how to use any of the Report.SaveAs* methods (SaveAsExcel, SaveAsHtml, SaveAsPDF, SaveAsWord, or SaveAsXML) to generate the report in the Business Central server and then write the report output to a file, see Report.SaveAsExcel(FileName: Text).

You can create an action on a page and set the action to run this code. When you run the action, the Export File dialog box opens. Choose Save to save the file to the client.

Report Data Type
Get Started with AL
Developing Extensions