0

Dynamics AX 2012 – Import CSV

Yesterday i had my third course day in AX Development III. We had to create a import functionality to import a list of word from a file to a table. This is wat i came up with.

It is not done yet cause it will also insert a “0” after the last imported word. I probably need to count the number of lines of the text file via a text buffer.

I am using commaIO but i have been reading that it is replaced by CommaTextIO, need to lookup more about this class.

Technical information: MSDN CommaTextIO

#    Dialog dialog;
            #    DialogField dialogFileName;
            #    Filename filename;
            #    FileIoPermission    permission;
            #    CommaIO             commaIO;
            #    container           readCon;
            #    str                 column1;
            #    WordTable           wordTable;
            #
            #    super();
            #
            #    delete_from WordTable;
            #
            #    dialog = new Dialog("Select CSV File");
            #    dialogFileName = dialog.addField("Filenameopen", "File Name");
            #    dialog.run();
            #
            #     if (dialog.run())
            #     {
            #        filename = dialogFileName.value();
            #        if(!filename)
            #        info("Filename must be filled");
            #
            #        permission = new fileIOpermission(filename,#io_read);
            #        permission.assert();
            #
            #        commaIO = new CommaIo(filename, #io_read);
            #        commaIO.inFieldDelimiter(';');
            #
            #        if (!commaIO)
            #        throw error("Error reading file");
            #
            #        try
            #        {
            #            if (commaIO)
            #            {
            #               readCon = commaIO.read();
            #
            #               while (commaIO.status() == IO_Status::OK)
            #               {
            #                   readCon = commaIO.read();
            #                   column1 = conPeek(readCon, 1);
            #                   wordTable.Word = column1;
            #
            #                   wordTable.insert();
            #               }
            #            }
            #        }
            #        catch
            #        {
            #            warning(strFmt("Importing file failed!"));
            #        }
            #    }
            #}

jack

Leave a Reply