Import CSV files into Business Central

Microsoft Dynamics 365 Business Central can import CSV files. It’s done with the wrongly named XMLPort (at least for this purpose) objects. The challenge is to get the indentions right, so here is a barebone XMLPort object that will read a CSV file. 

Image result for csv files

The important parts are the setting Format that uses the VariableText type and getting the initial indentation right.
Copy this into Visual Studio Code, and you’re up and running with CSV files and Business Central in no time.

xmlport 50100 "Import Demo CSV"
{
Caption = 'Import Demo CSV';
Direction = Import;
TextEncoding = UTF8;
Format = VariableText;
FieldDelimiter = '"';
FieldSeparator = ';';

schema
{
textelement(root)
{
tableelement(GenLine; "Gen. Journal Line")
{
AutoReplace = false;
AutoSave = false;
AutoUpdate = false;
XmlName = 'GenLine';
fieldelement(f1; GenLine."Debit Amount") { }
textelement(InvoiceNo){}
textelement(InvoiceDate){}
textelement(PostingDate){}
textelement(CustomerName){}
textelement(CustomerNo){}
trigger OnBeforeInsertRecord()
var
begin
// Brilliant code right here
end;
}
}
}
var
AwesomeVariables : Code[20];
}


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.