Read & process CSV files programmaticaly

LOCAL ReadCsvFile()
fmode := fmode.Open;
fstream := fstream.FileStream(‘c:\temp\test.csv’,fmode);
enc := enc.UTF8; // read text as UTF8 charset, can also be Default (Windows) or Ascii
reader := reader.StreamReader(fstream,enc);
Line := reader.ReadLine;
ColNo := 1;
CellValue := StringSplit(Line,’;’);
Column[ColNo] := CellValue;
ColNo += 1;
UNTIL Line = ”;
// Process columns
UNTIL reader.EndOfStream;

//variables: all .net vars RunClient=Yes
CellValue Text
Column Text, Dim 20
Line Text
ColNo Integer
reader DotNet System.IO.StreamReader.’mscorlib
fstream DotNet System.IO.FileStream.’mscorlib
fmode DotNet System.IO.FileMode.’mscorlib
enc DotNet System.Text.Encoding.’mscorlib

LOCAL StringSplit(VAR Text : Text[1024];Separator : Text[1]) Token : Text[1024]
Pos := STRPOS(Text,Separator);
Token := COPYSTR(Text,1,Pos-1);
IF Pos+1 <= STRLEN(Text) THEN
Text := COPYSTR(Text,Pos+1)
Text := ”;
Token := Text;
Text := ”;

Pos Integer

Also have a look at:


Access protected file share

There was a post, where a user wanted to get read/write acces to a file share outside the current domain from within Nav.

This can be done via .Net:

NetworkCredential := NetworkCredential.NetworkCredential(username, password, domain); // Credentials for domain 2
CredentialCache := CredentialCache.CredentialCache;
Uri := Uri.Uri(‘\\server’); // the server name from domain 2
CredentialCache.Add(Uri, ‘Basic’, NetworkCredential);
Dirs := SysDir.GetDirectories(‘\\server\directory’); // get folder list from the file share
FOR i:=1 TO Dirs.GetLength(0) DO
DirListTxt := DirListTxt + FORMAT(Dirs.GetValue(i-1))+’\’; //.net index starts with 0
MESSAGE(DirListTxt); // print out the dir list

NetworkCredential DotNet System.Net.NetworkCredential.’System
CredentialCache DotNet System.Net.CredentialCache.’System
Uri DotNet System.Uri.’System
Dirs DotNet System.Array.’mscorlib
SysDir DotNet System.IO.Directory.’mscorlib
DirListTxt Text
i Integer


D365BC – Data Backups – Part 2

Rapid Start cannot be found with the search function, also the Rapid Start Profile is missing. But the according pages are there:

  • Config Templates
  • Config Worksheet
  • Config Packages


The Config packages: There is a at least one demo config package containing most master data tables.


Screenshot at 2018-08-05 14-08-21

So there is a standard way for backing up and restore data with D365BC.



Dynamics 365 Business Central October ’18 release

Great news!

  • Cloud and On-Premise: means D365bc can be installed on a local server, you can make then backups of the database.
  • Extended VS-AL experience: support for .Net interop @ on-premise
  • Optimized user interface
  • Flow Filters, Limit Totals
  • Permission sets editable
  • Tenant admin
  • a.m.m.




D365BC – Data Backups

Currently D365BC is missing a couple of things, the licenses could be cheaper. But it’s the successor of Dynamics Nav. Now, some time after the release (name was changed quite often, feature list was changed very often, extension base tech was changed, a.s.o.) i decided to find at least one method for backing up data, a very missed feature. Maybe Microsoft will add that kind of feature in the future, nobody knows. But … in the meantime checkout this.

First i checked out the feature list of current D365BC, what can be used for that functionality or is an extension needed? So in the end i found the “Data Exports” in the finance module, a quite well known feature in NAV, which can be used for exporting data to text files. I worked with D365BC – Austria. Currently i don’t know what in detail are the differences between the localized versions, so please check, if data exports is available in “your” D365BC. 😉 If you cannot find it – should be, because the export report has a object number within the localization range – write to microsoft and let them know, that you want that feature in your localized version. 😀

Ok, starting with page “Data Exports” we can add one new data export, let’s call it BACKUP. Fill out the code and description fields.

Screenshot at 2018-07-22 14-41-11

Now we add a record definition set called “MASTER” for the master data. For that click on the according button, fill out the code and description fields.

One important thing: the dtd file, the file that contains the data structure. Without a dtd file it’s not possible to export data. In that case this can be done very simple, a concrete structure is not needed, only the xml declaration. Create a new text file, call it default.dtd, add following text line and save the file:

<?xml version=”1.0″ encoding=”UTF-8″?>

Now click on Import in menu group “Dtd File” and import that file. The file’s name is then added to the selected data record defition line.

Screenshot at 2018-07-22 14-53-05

Now lets go to the details. Click on button “Record Source”.

Screenshot at 2018-07-22 15-12-20.png

Here now add the master tables you want to export, e.g. tables 3, 4, 6, 9, 10, 13, 14, 15, 18, 23, 27 using the “New” button. With e.g. date filters you can limit the data to export. In the column “Export Filename” you get a suggested filename for the export file, per default ends with txt. Better change to csv. So the files can after the export easily opened in excel.

Also add all the fields, which you want to export, using the “Add” button in the Fields/Manage menu for the selected table.

That’s it. Go back to the parent page: Data export record definitions. There click on button “Export” in menu group “Process”.

Screenshot at 2018-07-22 16-06-38

After clicking OK a zip file is created and downloaded containing all the exported csv files. Alternatively you can schedule the export for a later point of time.

Screenshot at 2018-07-22 15-25-57

Also included is a file index.xml containing base data like company data, export name, list of exported files and the field names.

Screenshot at 2018-07-22 15-29-39

So, what we get here is a first backup solution for master data. At least we can export the current set of the master data at any time. You could create another data record definition for transaction data. After you have done that you’ll get in the end a complete backup solution for D365BC. 😀

Additional you could create a job queue entry for automatic export. Use report 11015 and set the recurring flags.

Screenshot at 2018-07-22 16-17-51

Set the request page Options as following:

Screenshot at 2018-07-22 16-18-04.png