Category Archives: CSV

AX2012 R2 – Import BAI2 Bank Statement

Hi Folks,

It’s time to update Functional stuff which I found from source by Andy Mooney on Importing BAI2 Bank Statement.

Please go through above source which would resolve your configuration problem before importing Bank statement.

Till then, Happy DaXing..

How to export table data in to csv file in AX 2012

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()
{
CommaTextIo file;
container line;
FileIoPermission perm;
#define.filename(@’filepath’)
#File
perm = new FileIoPermission(#filename, #io_write);
perm.assert();
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’;

if(custTable)
{
line = [custTable.name(),custTable.custGroup,custTable.creditMax];
file.writeExp(line);
}

}
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……..