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.
This method is supported only in Business Central on-premises.
[Ok := ] Report.SaveAsXml(FileName: Text)
The path and name of the file that you want to save the query to.
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.
You can use the SaveAsXML method on the global Report object and on Report variables. If, at design time, you do not know the specific report that you want to run, then use the global Report object and specify the report number in the Number parameter. If you know which report you want to run, then create a Report variable, set the Subtype of the variable to a specific report, and then use this variable when you call the SaveAsXML method.
When you call the SaveAsXML method, the report is generated and saved to "FileName." The request page is not shown.
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 Dynamics 365 Business Central service 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.
To resolve this issue, verify that the service account that is running the Dynamics 365 Business Central service instance has write permissions on the path.
This example shows how to use the SaveAsXML method to save a report as an .xml file on the Dynamics 365 Business Central service, and then download the file to a computer that is running the Dynamics 365.
var TempFile: File; Name: Text; NewStream: InStream; ToFile: Text; ReturnValue: Boolean; begin // Specify that TempFile is opened as a binary file. TempFile.TextMode(False); // Specify that you can write to TempFile. TempFile.WriteMode(True); Name := 'C:\Temp\TempReport.xml'; // Create and open TempFile. TempFile.Create(Name); // Close TempFile so that the SaveAsXML method can write to it. TempFile.Close; Report.SaveAsXML(406,Name); TempFile.Open(Name); TempFile.CreateInStream(NewStream); ToFile := 'Report.xml'; // Transfer the content from the temporary file on // server to a file on the client. ReturnValue := DownloadFromStream( NewStream, 'Save file to client', '', 'Excel File *.xml| *.xml', ToFile); // Close the temporary file. TempFile.Close(); end;
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.