A question received today was the following: is it possible from my extension in Dynamics 365 Business Central asking a user to select a local CSV file, load it and then managing the content accordingly to my business needs using CSV Buffer table?
In standard NAV code (C/AL) you can use CSV Buffer table to load a CSV file (without using an XMLPort) and then parsing its content line by line. You can load a CSV file by using the following C/AL code:
CSVBuffer.LoadData(PathOfYourCSVFile,Separator);
And what about AL code? Can I use CSV Buffer in my extension for Dynamics 365 Business Central (SaaS)? The answer is yes, but the way you read the file is different. If you try to use the LoadData method, this is the result:
Here you’re in the cloud and you need to use Streams for accessing files. This is the code that works in a cloud Dynamics 365 Business Central environment:
The key here is to create an InStream object, reading the CSV file to the InStream object and then call the LoadDataFromStream method of the CSV Buffer table. Then you can parse the CSV content exactly like on the old C/AL code.
Very useful information. I needed to upload a file into the cloud and this post just saved me a lot of time. Thanks
LikeLike
What about exporting a CSV file from BC using the CSV buffer?
LikeLike
How to skip the first line? Thanks
LikeLike
Just use an skip like:
var
StartImport: boolean;
begin
repeat
if StartImport = true then begin
(your code for the import)
end
else
StartImport = true;
until (whatever).next = 0;
So it will start with a false on “StartImport” and skip the first line because he is just going into the else and will set the StartImport on true. After this he will repeat the process with your import until the import is done.
LikeLike