Microsoft 365 Business Central: BLOBS and Data Streams in AL

Jared Drueco | July 4, 2022

One of the reports I worked on this week required me to read data from a Blob field on a Business Central page. A BLOB (Binary Large Object) is a complex data type in Business Central with a variable-length allowing it to store text, bitmaps, or user-defined files with a max size of 2 GB. I learned that in order to interact with this data type, one needs to use stream objects as a pipeline for data flow.

Interacting with a BLOB

In this blog post, I will be demonstrating how to read text from a BLOB field in Business Central by utilizing the InStream object (InStream is another data type in Business Central). We use this object because it contains a method ‘Read()’ which allows us to read the binary data from the BLOB.

As we can see on the Sales Invoice page and on the Sales Header table, there is a BLOB field called ‘Work Description’. This is ultimately the field we want to access/read text from.

Next, we create a procedure (a local function) that creates a Record of the Sales Header table as a parameter, with a return type of ‘Text’ which will be the text read from the BLOB. The InStream object is declared here also.

Adding to our code, we use the Clear() method on the current text (so that the previous text read is up to date), and we calculate the BLOB field on the Sales Header table. After checking if the field is not empty, we create the InStream object linked to the BLOB we want to read from. Lastly, we use the Read() method of the stream object to read the BLOB data and our procedure returns it as text.  

To prove that we’ve successfully read the data from the BLOB into text, I’ve added a trigger that prints the ‘Work Description’ on the current page/record.

References

BLOB Documentation

1. https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/blob/blob-data-type

Videos By Erik Hougaard:

1. https://www.youtube.com/watch?v=Hmj9ps7J5hs
2. https://www.youtube.com/watch?v=fcUeYUpO2j