In last article we created tables and pages required to store attachment in #msdyn365bc or #msdynnav.
If you want to see other articles in this series please check here.
In this article we will understand How to use Base64 Conversion in #msdyn365bc and #msdynnav.
To transfer files, we cannot do it as a file but Base 64 can help us to do the magic.
What is Base 64?
- Base64 is the most popular binary-to-text algorithm used to convert data as plain text in order to prevent data corruption during transmission between different storage mediums.
- In addition, it is often used to embed binary data into text documents such as HTML, CSS, JavaScript, or XML.
Read More about Base 64 here.
For File Handing we will add functions to Export and Import attachment in Business Central.
For Importing Attachment there are two ways based on what approach you are using.
Method 1 - Using TempBlob Table.
The Procedure accepts a Text parameter and we will use the build in function FromBase64String to convert the Text value to a Blob Field.
Later on we will transfer that blob to our Record.
The Text value that passed in the procedure is a Bit 64 value.
Method 2 - Using Temp Blob Codeunit.
As we all know Microsoft have planned to remove the Tempblob table from the Base application extension and will be replaced by Temp Blob Codeunit.
Additionally Microsoft have added a separate Codeunit for Base 64 Convert which have multiple overloads.
- 4 Overloads for FromBase64.
- 7 Overloads for ToBase64.
I am sure you will find the overload that you will like in your scenario. we will use one that fits to the scenario that we are working on.
For Exporting/Downloading Attachment from #msdyn365bc we will add a procedure.
This procedure will check if there a attachment and if yes then Put in stream and then download from Stream to the client.
To make these functions available for users we will add these in pages that we have created in Last article.
We have one more step before we start testing the sample that we are developing.
Another extremely useful contribution. Thanks, Saurav!
ReplyDeleteThankyou Justin for the comment. Hope you are also noticing new content on YouTube channel. https://www.youtube.com/@SauravDhyani
Delete