Dynamics 365 Business Central: loading Configuration Packages from AL (part 2)

More than one year ago I wrote this post on how to import directly from AL code a Configuration Package (.rapidstart) file.

This code uses the ImportRapidStartPackageStream method declared in the “Config. Package – Import” codeunit as follows:

I remember to have suggested in the past some possible improvements on this codeunit, like adding the possibility to import multiple files at once (maybe from a ZIP file) and to export a Configuration Package directly from code.

By checking some days ago for the same functionality in Dynamics 365 Business Central version 16, with a bit of surprise I’ve discovered that:

  1. “Config. Package – Import” codeunit is always the same (no new methods or implementations added)
  2. A new method called ImportPackageXMLFromStream was added in “Config. XML Exchange” codeunit

Using this second method is quite tricky, because if you directly load the .rapidstart package into an InStream object and use this new method, you will have an XML error like “A call to System.Xml.XmlDocument.Load failed with this message: Root element is missing“.

The .rapidstart file is compressed, so you need to decompress it before calling the new method. The code that works by using the ImportPackageXMLFromStream in Config. XML Exchange codeunit is as follows:

Please don’t ask me why Microsoft added this new method here too

However, there’s still an open problem: there’s no a native method for exporting a Configuration Package from a SaaS environment directly from code. Codeunit “Config. XML Exchange” has the following methods:

  1. ExportPackage
  2. ExportPackageXML
  3. ExportPackageXMLDocument

but they’re all for on-premise usage (cannot be used on SaaS):

I think that adding a new ExportPackageXMLFromStream method could be useful on many scenarios (ticket opened here), exactly like avoiding different methods on different codeunits that does quite the same things

Comment List