How To Read Data From CSV File using X++

          


  public static void main(Args _args)

    {

         #File

        IO  iO;

        str SO_ID;

        str Name;

        Table1 _table1;

        FilenameOpen        filename = @"C:\Users\Adminfdc3207d2d\Desktop\info.csv";

        //To assign file name


        Container           record;

        boolean first = true;

        ;


        iO = new CommaTextIo(filename,#IO_Read);

        if (! iO || iO.status() != IO_Status::Ok)

        {

            throw error("@SYS19358");

        }


        while (iO.status() == IO_Status::Ok)

        {

            record = iO.read();// To read file

            if (record)

            {

                if (first)  //To skip header

                {

                    first = false;

                }

                else

                {


                    SO_ID = conpeek(record, 1);// fetch records from first column


                    Name = conpeek(record, 2); // fetch records from second column


                    

                    _table1.Nme = SO_ID; // Table1 stores records of first column in Nme field.

                    _table1.insert();

                    info("File inserted in the Table");

                }


            }

        }

}

Comments

Popular posts from this blog

How to Create a wizard in x++ d365

how to post trade agreement journals automatically using x++ code

X++ code to CREATE AND POST A TRADE AGREEMENT IN MICROSOFT DYNAMICS 365 in D365 F & O