I’ve received in the last days a request from a forum user asking for a way to automatically loading demo data in an extension, maybe embedding a data file inside the extension package and load it when needed, for example during the install phase.
Unfortunately you cannot embed data files inside your binary .app file and read them from the binary .app file folder structure. I’ve promised a personal response and here it is. I think there are different ways of loading demo data for an extension, but the way I normally suggest is the following:
I’ve talked about loading Configuration Packages from AL by using Streams in the past here and here. To load demo data for your extension, you can do the same.
As a first step, create an Azure Storage Account and inside this storage account create a container for hosting blobs (here called demodata). For this container, set Public Access Level = Blob :
In this way, your container will have anonymous access for reading the blob content. In this way, you can avoid to share access keys for loading demo data (obviously, this is up to you if you don’t want this but instead you prefer to add an access key).
When the container is created, you can create a new Configuration Package. Here as a demo I’m using an extension that has a table called WorkItem:
Create your demo data (for example from Excel) and then import the data to your package:
Here I have 9 demo records. Then, export the package with your data as a .rapidstart file and then upload this file to your Azure Blob Storage container:
You will now have a public url for accessing your package file in the form of
Now the code part. On my extension, I create an Import Demo Data action for loading the demo data from the Rapidstart package (but you can trigger it also automatically from your code):
This code calls a codeunit that does all the data loading process. The code is as follows:
I think it’s quite self-explanatory. By using the HttpClient object it downloads the package from the storage account to a stream and then it calls the ImportAndApplyRapidStartPackageStream method of the Config. Package – Import codeunit for loading and applying the package to the database.
Your demo data are automatically loaded to your extension.
As said before, you can load demo data to an extension with different ways, but the way described here is normally my first suggestion because: