AL Extensions: Importing and Exporting Media Sets

One of the things that has changed when you are building V2 extensions for a cloud environment is that you cannot access most functions that work with physical files.
This presents a bit of a challenge when it comes to working with the media and media set field types, as the typical approach is to have an import and export function so that a user can get pictures in and out of the field.
An example of this is the Customer Picture fact box that’s on the Customer Card:
As you can see, the import and export functions in C/Side leverage the FileManagement codeunit in order to transfer the picture image to and from a physical picture file. These functions are now blocked.
So…..we have got to take another approach. Enter streams.
Using the in and out stream types we can recreate the import and export functions without using any of the file based functions.
An import function would look like the following. In this example, the Picture field is defined as a Media Set field.

local procedure ImportPicture();
   PicInStream: InStream;
   FromFileName: Text;
   OverrideImageQst: Label 'The existing picture will be replaced. Do you want to continue?', Locked = false, MaxLength = 250;
   if Picture.Count > 0 then
     if not Confirm(OverrideImageQst) then
  if UploadIntoStream('Import', '', 'All Files (*.*)|*.*', FromFileName, PicInStream) then begin
    Picture.ImportStream(PicInStream, FromFileName);

The UploadIntoStream function will prompt the user to choose a local picture file, and from there we upload that into an instream. At no point do we ever put the physical file on the server. Also note that the above example will always override any existing picture. You do not have to do this as media sets allow for multiple pictures. I’m just recreating the original example taken from the Customer Picture page.
For the export we have to write a bit more code. When using a Media Set field, we do not have access to any system function that allows us to export to a stream. To deal with this all we need to do is loop through the media set and get each of the corresponding media records. Once we have that then we can export each of those to a stream.
That would look like this:

local procedure ExportPicture();
   PicInStream: InStream;
   Index: Integer;
   TenantMedia: Record "Tenant Media";
   FileName: Text;
   if Picture.Count = 0 then
   for Index := 1 to Picture.Count do begin
      if TenantMedia.Get(Picture.Item(Index)) then begin
         if TenantMedia.Content.HasValue then begin
            FileName := TableCaption + '_Image' + format(Index) + GetTenantMediaFileExtension(TenantMedia);
            DownloadFromStream(PicInstream, '', '', '', FileName);

We use the DownloadFromStream function to prompt the user to save each of the pictures in the media set. As in our first example, there are no physical files ever created on the server, so we’re cloud friendly!
You may notice that I use the function GetTenantMediaFileExtension in the export example to populate the extension of the picture file. Since the user can upload a variety of picture file types, we need to make sure we create the file using the correct format.

The function to do this is quite simple, however there is no current function in the product to handle it, so you’ll have to build this yourself for now. Hopefully in the near future this function will be added by Microsoft.

local procedure GetTenantMediaFileExtension(var TenantMedia: Record "Tenant Media"): Text;
   case TenantMedia."Mime Type" of
      'image/jpeg' : exit('.jpg');
      'image/png' : exit('.png');
      'image/bmp' : exit('.bmp');
      'image/gif' : exit('.gif');
      'image/tiff' : exit('.tiff');
      'image/wmf' : exit('.wmf');

Until next time, happy coding!



Well, it finally happened…..
The Dynamics 365 for Financials extension (or app…..your choice) that I’ve been working on has finally made it to AppSource! You can check out our listing here.
BuildFood – Recipes is the first extension from IndustryBuilt Software Corp., who also happen to make JustFood. The extension focuses on the needs of the small bakeries out there, and as the marketing gurus say, it can

“manage recipes, create ingredient declarations, track allergens and calculate nutrients.”

With the extension being validated back in November, it has been a somewhat lengthy wait before seeing it published, but it’s awesome to see it available now! When we first formed the “extension team” as it was first referred, we weren’t sure what to expect from this “new way” of building solutions, and it became evident early on that we needed to tackle everything (marketing, product design, development) with fresh eyes and a new point of view. I think everyone involved has done a fantastic job of that if I do say so!
So……we’re published. Cool….but we are not stopping yet! We’re not too far from submitting the next version of BuildFood – Recipes to AppSource so stay tuned for that! Some great new features coming in the next version! We’re also working on our second extension, but I’m not giving away any details on that until marketing has their chance to let loose with it. 🙂
Oh, if you want to know more about BuildFood, click here!
Happy coding…

Project 'Madeira' comes to Canada

Announced yesterday at Microsoft’s Worldwide Partner Conference, the Project ‘Madeira’ preview, an integral part of the upcoming Microsoft Dynamics 365 platform, has been launched to Canadian users! By signing up with a Canadian Office 365 account, you’ll be able to access the platform with a Canadian-centric database.
Click here and sign up today!
Also announced, is that the product will be launching to the US and Canada in the Fall of 2016.
For more info on what Project ‘Madeira’ is all about, check out my previous post on the topic.

Hello Project "Madeira"

Today, Microsoft unveiled a major effort they’ve been working on, codenamed Project “Madeira”.
What is it? Simply put…..this is a preview of Microsoft’s offering of a fully cloud-based ERP system. Geared towards small and mid-sized companies, Project “Madeira” is a simple to sign-up, no footprint browser-based software package that provides all of the tools necessary to manage a business……and it’s available on your mobile device too.
Even simpler put……….it’s FREAKIN’ AWESOME!
Oh, and it is DEEPLY integrated into Office365 as well, so managing emails, or exporting data to Excel is a snap on any device!
If that’s not enough, it’s incredibly easy to connect Power BI to your Project “Madeira” system for incredible insights into your business data.
Currently, the preview is only available in the US, but I imagine it’s only a matter of time for that to change. If you just can’t wait, sign up for a free 1 month trial US O365 account to get access now.
A goal of Project “Madeira” is to make it easy for companies to move to this new platform, and this is evident in the sign up process. You can choose to create an empty company, and then simply upload your existing data into it. For those that are using QuickBooks, there is an extension that once enabled, lets you upload data directly from an Intuit Interchange Format (IFF) file. If that doesn’t float your boat, or if you need to ‘clean’ your data first, you can also use Excel files.
Extensions……what are those you ask? Think of these as pieces of functionality that you can turn on and off. This not only means that you can run your ERP in the cloud, but you can tailor your system with the functionality that you need!
Currently, there are 3 extensions available in the preview, but you can rest assured that many more are on the way:

Ok, enough reading about it, go try out the preview!!.

© 2020 NAV Bits and Bytes

Theme by Anders NorénUp ↑