{"title":"Report.SaveAsXml(Text) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/report/reportinstance-saveasxml-method/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/report/reportinstance-saveasxml-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/report/reportinstance-saveasxml-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Saves the resulting data set of a query as an .xml file.The following code shows the syntax of the SaveAsXml method.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"Report.SaveAsXml(Text) Method","slug":"reportsaveasxmltext-method","at":0,"chars":3512},{"level":2,"title":"Syntax","slug":"syntax","at":411,"chars":63},{"level":2,"title":"Parameters","slug":"parameters","at":474,"chars":195},{"level":2,"title":"Return Value","slug":"return-value","at":669,"chars":238},{"level":2,"title":"Remarks","slug":"remarks","at":907,"chars":1684},{"level":3,"title":"Error conditions","slug":"error-conditions","at":1707,"chars":884},{"level":2,"title":"Example","slug":"example","at":2591,"chars":787},{"level":2,"title":"Related information","slug":"related-information","at":3378,"chars":134}],"text":"# Report.SaveAsXml(Text) Method\n> Version: _Available or changed with runtime version 1.0._\nSaves 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.\n> NOTE\n> This method is supported only in Business Central on-premises.\n## Syntax\n```al\n[Ok := ]  Report.SaveAsXml(FileName: Text)\n```\n## Parameters\nReport\nType: report-data-type\nAn instance of the report-data-type data type.\nFileName\nType: ../text/text-data-type\nThe path and name of the file that you want to save the query to.\n## Return Value\n*[Optional] Ok*\nType: ../boolean/boolean-data-type\ntrue 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.\n## Remarks\nYou 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 static version of the SaveAsXml method, see Report.SaveAsXml(Integer, Text [, var Record])<report-saveasxml-method>.\nWhen you call the SaveAsXML method, the report is generated and saved to the file specified in \"FileName.\" The request page is not shown.\n> NOTE\n> 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/file-download-method method to download the .pdf file from the computer that is running the Business Central server to the computer that is running the client.\n### Error conditions\nThe method can fail in the following three ways:\n If the destination folder specified in FileName does not exist,\n If the file specified in FileName is being used, or\n If the Business Central server process does not have permission to write to the file specified in FileName.\nIf the report you specify does not exist, then a run-time error occurs.\nIf the destination folder that you specify in FileName does not exist, then you get the following error: The specified path is invalid.\nIf the file that you specify in FileName is being used, then you get the following error: An I/O exception occurred during the operation.\nIf 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.\n## Example\nThis example shows how to use the static SaveAsXml method in a safe way (where no errors occur).\n```al\nvar\n    FileNameAndPath: Text[250];\n    MyReportInstance: Report MyReport;\nbegin\n    // setup that FileNameAndPath is valid to write to\n\n    MyReportInstance.SaveAsXml(FileNameAndPath);\nend;\n```\nFor 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)<report-saveasexcel-method>.\nYou 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.\n## Related information\nreport-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}