Dynamics AX Blog - Posts from July 2015

These posts are machine-translated.
Currently, only posts from »July 2015« are displayed Filter entfernen

Import data from csv-file to Dynamics AX

Using the CommaTextIo class you can import CSV files into Dynamics AX. The job shows a simple example of using this class.

static void importCSVFile(Args _args)
{
    Filename fileName = @"c:	empcsvimport.csv";
    CommaTextIo commaTextIo = new CommaTextIo(fileName, "r");
    container lineCon;

    commaTextIo.inFieldDelimiter(';');
    commaTextIo.inRecordDelimiter(' ');
    while (commaTextIo.status() == IO_Status::OK)
    {
        lineCon = commaTextIo.read();

        info(strFmt("%1 %2 %3", conPeek(lineCon, 1), conPeek(lineCon, 2), conPeek(lineCon, 3)));
    }
}

In principle, this would also work with the TextIo class (or AsciiIo), but it must be noted that these classes can provide unexpected results when, for eample the inFieldDelimiter - in my example a semicolon - occurs within a text.

 

The following sample file would otherwise be processed, as expected from the developer. The third column in the third row would be interpreted as two columns by the read()-method.

100;450,00;Customername1
101;1200,00;Customername2
102;50,28;"Customername 3; Second customername"

 
 
 

 

 
 
 
Posts of the actual month
July 2015
MoTuWeThFrSaSu
 12345
6789101112
13141516171819
20212223242526
2728293031 
 
© 2006-2025 Heinz Schweda | Imprint | Contact | German version | Mobile version
In order to provide you with better service, this site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.