{"title":"Query.SaveAsXml(Integer, Text) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/query/query-saveasxml-integer-string-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/query/query-saveasxml-integer-string-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/query/query-saveasxml-integer-string-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.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"Query.SaveAsXml(Integer, Text) Method","slug":"querysaveasxmlinteger-text-method","at":0,"chars":1996},{"level":2,"title":"Syntax","slug":"syntax","at":229,"chars":79},{"level":2,"title":"Parameters","slug":"parameters","at":308,"chars":302},{"level":2,"title":"Return Value","slug":"return-value","at":610,"chars":233},{"level":2,"title":"Remarks","slug":"remarks","at":843,"chars":173},{"level":2,"title":"Open, Read, or Close semantics","slug":"open-read-or-close-semantics","at":1016,"chars":276},{"level":2,"title":"Example","slug":"example","at":1292,"chars":571},{"level":2,"title":"Related information","slug":"related-information","at":1863,"chars":133}],"text":"# Query.SaveAsXml(Integer, Text) Method\n> Version: _Available or changed with runtime version 1.0._\nSaves the resulting data set of a query as an .xml file.\n> NOTE\n> This method is supported only in Business Central on-premises.\n## Syntax\n```al\n[Ok := ]  Query.SaveAsXml(Number: Integer, FileName: Text)\n```\n## Parameters\nNumber\nType: ../integer/integer-data-type\nThe 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.\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 SaveAsXml succeeded, otherwise false. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.\n## Remarks\nWhen the SaveAsXML method is called, the dataset is generated and then saved in XML format in the file and location that is designated by the FileName parameter.\n## Open, Read, or Close semantics\nThe SaveAsXML method can be called at any place in the code and does not require that the Open, Read, or Close methods are called before it. See query-saveasxml-integer-outstream-method#open-read-or-close-semantics-with-the-saveasxml-method.\n## Example\nThe following example shows how to save a query with the name My Customer Query as an .xml file. The file is given the name myquery.xml and is saved on the c: drive of the computer running Dynamics 365 Business Central service.\n```al\nvar\n    MyCustomerQuery: Query \"My Customer Query\";\n    OK: Boolean;\n    Text000: Label 'Query was not saved.';\nbegin\n    OK := MyCustomerQuery.SaveAsXML(Query::MyCustomerQuery, 'c:\\myquery.xml');\n    if not OK then\n      Error(Text000);\nend;\n```\nIf the file cannot be saved, then the follow message appears:\nQuery not saved.\n## Related information\nquery-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}