A CSV is a comma separated values file, which allows data to be saved in a table structured format. Traditionally they take the form of a text file containing information separated by commas.
You can export table data outside of AX into file which separates value of field with a comma. e.g., “Mohammed”, “Raziq”, “Ali”, “Hussain”,”OU”, “MCA”,”27″. Row data are separated by commas.
Lets proceed with an example to understand how to export table into CSV file. The following code writes selected table data into file with proper validations.
CommaTextIo class plays major role in writing/reading file csv in AX 2012
public void exportCSVFile()
perm = new FileIoPermission(#filename, #io_write);
file = new CommaTextIo(#filename, #io_write);
if (!file || file.status() != IO_Status::Ok)
throw error(“@SYS19358”);//throws error if file path is not found
select * from custTable where custTable.AccountNum == ‘0010’;
line = [custTable.name(),custTable.custGroup,custTable.creditMax];
Assign null value to file object once you are done with writing.
file = null;
Hope you understood this simple code to write data into CSV file.
Thanks & Happy DaXing……..