How to generate csv file in Ax 2012

Description:-

here i have create simple code to generate csv file in Ax 2012. here i have generate product master and name in the csv file.

static void dev_Export_ItemData(Args _args)
{
    CommaIo                         myFile;
    container                       myCon;
    FileIoPermission                perm;

    #File
    #Properties
    #AOT
    #define.ExampleFile(@"Filepath + Filename + FileExtension")
    EcoResProduct EcoResProduct;
    ;
    perm = new FileIoPermission(#ExampleFile, #io_write);
    perm.assert();
    myFile= new CommaIo(#ExampleFile, #io_write);
    myFile.outFieldDelimiter(',');

    myCon = ["Item number","Search name"];
    myFile.writeExp(myCon);
    while select * from EcoResProduct
    {
        myCon=[EcoResProduct.DisplayProductNumber,EcoResProduct.SearchName];
        myFile.writeExp(myCon);
    }
}

Related Posts

Previous
Next Post »

1 comments:

comments
June 18, 2018 at 1:01:00 PM GMT+5:30 delete

//2nd way
Query query;
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
QueryRun queryRun;
CommaIO commaIO;
FileName fileName;
InventTable inventTable;
;

fileName = "D:\\Dipen Task\\" + "ItemDetails" + ".csv"; //Destination of the file
commaIO = new CommaIO(fileName,'W');

query = new Query();
queryBuildDataSource = query.addDataSource(tablenum(InventTable));
queryBuildRange = queryBuildDataSource.addRange(fieldnum(InventTable,ItemId)); //Range

queryRun = new QueryRun(query);

commaIO.write("ItemId","Item Type"); //Header of the CSV File
//Loop to insert values in the csv from the table
while(queryRun.next() )
{
inventTable = queryRun.get(tablenum(InventTable));
commaIO.write(inventTable.ItemId,enum2str(inventTable.ItemType));
}

WINAPI::shellExecute(fileName);

Reply
avatar

Thanks for comments.....