How to create csv file in Dynamics AX 2012 Through X++

     #File
     CommaTextIo            commaTextIo_File;
     container                    file_Line;
     CustTable                   custTable;
     FileIoPermission       permission;
     Filename                    fileName            = @"C:\\Temp\\FileName.csv";
    
     permission                = new FileIoPermission(fileName, #io_write);
     permission.assert();
     commaTextIo_File   = new CommaTextIo(fileName, #io_write);
     if (!commaTextIo_File || commaTextIo_File.status() != IO_Status::Ok)
     {
        throw error("Error when try create file.");
     }
     commaTextIo_File.outRecordDelimiter('\r\n');
     commaTextIo_File.outFieldDelimiter(',');
     while select firstonly10 CustTable
     {
         file_Line = [CustTable.AccountNum,CustTable.name()];
         commaTextIo_File.writeExp(file_Line);
     }
     CodeAccessPermission::revertAssert();
     info(strFmt("File created in the following path: %1.", filename));

Comments

Popular posts from this blog

How to loop through enum in dynamics ax 2012 using x++

How to read from csv file in Dynamics AX 2012 Through X++

How to Create Transfer Journal in Dynamics AX 2012 Through X++