Tuesday 19 September 2017

write to csv from ax

static void customerExportCsv(Args _args)
{

    CommaTextIo file;
    container line;
    FileIoPermission perm;
    CustTable                   custTable;
        FreeText                address;
        TaxRegistrationNumber_IN gstNo;


    #define.filename(@"C:\cust.csv")
    #File
    perm = new FileIoPermission(@"C:\cust.csv", "w");
    perm.assert();
    file = new CommaTextIo(@"C:\cust.csv", "w");

    if (!file || file.status() != IO_Status::Ok)
    {
    throw error("@SYS19358");//throws error if file path is not found
    }

    while    select custTable
    {
        gstNo = TaxRegistrationNumbers_IN::find(TaxInformation_IN::findDefaultbyLocation(DirPartyTable::findRec(CustTable::find(custTable.AccountNum).Party).PrimaryAddressLocation).GSTIN).RegistrationNumber;
        address = DirParty::primaryPostalAddress(custTable.Party).Address;

    if(custTable)
    {
        line = [custTable.AccountNum,custTable.name(),custTable.InventSiteId,address,gstNo];
        file.writeExp(line);
    }
    }
   info("done");
}



Read file dynamically.

 int currentFileCount;
   
     System.String[] filePaths = System.IO.Directory::GetFiles(@"C:\folder\", "*.CSV*", System.IO.SearchOption::AllDirectories);
   fileNameOpen = filepaths.GetValue(currentFileCount);

1 comment: