The new AL Language version 14.2 introduces the possibility to package resources inside an AL extension and use those resources from your AL code. This feature is a great addition because it permits you to add images, data file, configuration packages and more into your AL extension’s package and then use them at runtime (during the installation phase or in your standard code).
To add resources in an AL extension, you need to create inside your AL project a folder (or a set of folders) where you will place your resources and then list those folders in the new resourceFolders property in the extension’s app.json file.
To give you an example, here is an extension where I have created a Resources folder with some subfolders on it. As you can see, I have a data subfolder containing a txt file and a json file and an images subfolder containing a PNG file.
In the app.json file, I simply set “resourceFolders”: [“Resources”] (top level folder containing my extension’s resource files):
If you have more than one top level folders for resources, simply list them in the resourceFolders array.
To access those resources from AL code, you can use the new NavApp.GetResource method and its derivates:
procedure GetResource(ResourceName: Text, var ResourceStream: InStream, [Encoding: TextEncoding]) : Retrieves a resource that was packaged with this app and loads it into the specified InStream
procedure GetResourceAsText(ResourceName: Text, [Encoding: TextEncoding]): Text : Retrieves the specified resource as Text
procedure GetResourceAsJson(ResourceName: Text, [Encoding: TextEncoding]): JsonObject : Retrieves the specified resource as a JsonObject
Here a snippet of code that shows how to load the data of the resources I’ve packaged with my extension from AL code:
As you can see, it’s very easy…
Please remember that resources can only be accessed within the scope of the app that contains them. This means that there is no way to access the resources of another app.
Names for resources (data file) must be unique for folders, otherwise you will have an error.
Obviously, there are limits on the size of the resources and the extension’s file containing them (entire package):
All resources that you will package inside an extension are virus scanned at server side (security first ).
Original Post https://demiliani.com/2024/12/11/dynamics-365-business-central-using-resources-in-al-extensions/