Monday, March 7, 2016

X++ Create a simple CSV file (part 2)

Hi I found another way to write CSV in a job which is simpler than the previous one I posted.

Refer to Santosh Kumar Singh's blog

Let say I re-post Santosh Kumar Singh's code again with a bit layout adjust. Thanks him for a nice code.


CommaTextIo file;
container line;
CustTable custTable;
#define.filename(@'C:\Test\TestFile.csv')
#File
;

file = new CommaTextIo(#filename, #io_write);
if (!file || file.status() != IO_Status::Ok)
{
   throw error("File cannot be opened.");
}

while select AccountNum, Name from custTable
{
   line = [custTable.Name,
           custTable.Name];
   file.writeExp(line);
}

info(strFmt("File %1 created in specified folder.", #filename));
}

No comments:

Post a Comment