Problem Statement:
While I was working on some custom EFT project, I thought of using XMLPort as it is the safest and easiest method to get the data successfully directly from the tables.
Unfortunately, XMLPort is not supported to work on WebClient and I was stuck with writing code to do exactly what XMLPort would do.
Also, another issue that Business Central d extension support is using File methods i.e Open, Write, Close, etc.
Introduction:
In Business Central even if you're not given explicit rights to deal with files directly there are streams using which we can be downloaded as files. Enough of introduction, let's start working now!
Books & References:
https://docs.microsoft.com/en-us/dynamics-nav/feature-limitations-of-the-microsoft-dynamics-nav-web-client
Pre-requisites:
Demonstration:
1. Creation of File Contents:
In this case, I've simply text string 'Hello World!'
Although it's perfectly possible to create more complicated strings such as XML contents using a combination of loops and text manipulating functions as needed.
2. Creation of Streams:
Using TempBlob.Blob.CREATEOUTSTREAM(Var_OutStream) initialize the OutStream.
Using Var_OutStream.WriteText(Var_FileContent) write the text to the BLOB
Using TempBlob.Blob.CREATEINSTREAM(Var_InStream) read the contents of BLOB to InStream variable.
3. Downloading the contents of the Streams to a file:
Using DownloadFromStream(Var_Instream,FileName.FileExtension) download the contents of the InStream to a file.
Output:
Conclusion:
That's exactly how I was able to create a Custom Text File and download it in Business Central.
Sometimes solutions are right under our nose but you gotta work hard to find it.
Cheers!
While I was working on some custom EFT project, I thought of using XMLPort as it is the safest and easiest method to get the data successfully directly from the tables.
Unfortunately, XMLPort is not supported to work on WebClient and I was stuck with writing code to do exactly what XMLPort would do.
Also, another issue that Business Central d extension support is using File methods i.e Open, Write, Close, etc.
Introduction:
In Business Central even if you're not given explicit rights to deal with files directly there are streams using which we can be downloaded as files. Enough of introduction, let's start working now!
Books & References:
https://docs.microsoft.com/en-us/dynamics-nav/feature-limitations-of-the-microsoft-dynamics-nav-web-client
Pre-requisites:
- VS Code
- AL Language Extension
- Microsoft Dynamics Business Central.
Demonstration:
1. Creation of File Contents:
In this case, I've simply text string 'Hello World!'
Although it's perfectly possible to create more complicated strings such as XML contents using a combination of loops and text manipulating functions as needed.
2. Creation of Streams:
Using TempBlob.Blob.CREATEOUTSTREAM(Var_OutStream) initialize the OutStream.
Using Var_OutStream.WriteText(Var_FileContent) write the text to the BLOB
Using TempBlob.Blob.CREATEINSTREAM(Var_InStream) read the contents of BLOB to InStream variable.
3. Downloading the contents of the Streams to a file:
Using DownloadFromStream(Var_Instream,FileName.FileExtension) download the contents of the InStream to a file.
Output:
Conclusion:
That's exactly how I was able to create a Custom Text File and download it in Business Central.
Sometimes solutions are right under our nose but you gotta work hard to find it.
Cheers!
Comments
Post a Comment
Let me know your comments below. I'll try my best to answer your comment