AX - Import flat file job

tatic void ImportFileWithDialog(Args _args)
{
    AsciiIO     asciiIO;
    Filename    filename;
    NoYesId     skipFirstLine;
    Container   line;
    Dialog      dialog;
    DialogField dialogFileName, dialogSkipFirstLine;
    ;

    dialog                  = new Dialog("Import file");
    dialogFileName          = dialog.addField(typeid(Filenameopen), "File name");
    dialogSkipFirstLine     = dialog.addField(typeid(NoYesId), "Skip first line");
    dialog.run();

    if (dialog.run())
    {
        filename      = dialogFileName.value();
        skipFirstLine = dialogSkipFirstLine.value();
    }

    asciiIO = new AsciiIO(filename, 'R');

    if (!asciiIO || asciiIO.status() != IO_Status::Ok )
    {
        throw error (strfmt("@SYS19312",filename));
    }


    ttsbegin;
    asciiIO.inRecordDelimiter('\r\n');
    asciiIO.inFieldDelimiter(',');

    if (skipFirstLine)
        line = asciiIO.read();

    while (asciiIO.status() == IO_status::Ok)
    {
        line = asciiIO.read();

        if (line)
        {
            info(conpeek(line,1));
            info(conpeek(line,2));
        }
    }
    ttscommit;
}

Comments

Popular posts from this blog

Dynamics Ax 2012 Interview Questions:

Oops concept in AX