Friday, June 11, 2021

Create and export csv in D365 FO X++

CODE :

        System.IO.Stream        stream;

        TextStreamIo            io;

        System.IO.StreamReader  reader;

        XML                     fileContent;


        io = TextStreamIo::constructForWrite();

        io.write(strFmt("Personnel number,Name"));

        HcmWorker HcmWorker;

        HcmWorker = null;

        while select HcmWorker

        {

            io.write(strFmt("%1,%2",HcmWorker.PersonnelNumber,HcmWorker.name()));

        }

        stream = io.getStream();

        stream.Position = 0;

        reader = new System.IO.StreamReader(stream);

        filecontent = reader.ReadToEnd();


        File::SendStringAsFileToUser(fileContent, 'Template.csv');