Monday 4 June 2018

Customer Details Exporting in Ax 2012

static void customerExport(Args _args)
{

    SysExcelApplication         application;
    SysExcelWorkbooks           workbooks;
    SysExcelWorkbook            workbook;
    SysExcelWorksheets          worksheets;
    SysExcelWorksheet           worksheet;
    SysExcelCells               cells;
    SysExcelCell                cell;
    int                         row;
    container                   conCompanies = [ 'USMF', 'DEMF', 'DAT' ];

    CustTable                   custTable;
    DirPartyTable               dirPartyTable;
    LogisticsLocation           logisticsLocation;
    LogisticsPostalAddress      postalAddress;
    LogisticsElectronicAddress  electronicAddress;


    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    workbook = workbooks.add();
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);

    cells = worksheet.cells();
    cells.range('A:A').numberFormat('@');
    cell = cells.item(1,1);
    cell.value("AccountNum");
    cell = cells.item(1,2);
    cell.value("CustGroup");
    cell = cells.item(1,3);
    cell.value("Name");
    cell = cells.item(1,4);
    cell.value("Currency");
    cell = cells.item(1,5);
    cell.value("counrtyRegionId");
    cell = cells.item(1,6);
    cell.value("Address");
    cell = cells.item(1,7);
    cell.value("Type");
    cell = cells.item(1,8);
    cell.value("Locator");
    row = 1;

    while select crossCompany:conCompanies * from custTable join dirPartyTable  where custTable.Party == dirPartyTable.RecId
                        join electronicAddress
                            where electronicAddress.RecId == dirPartyTable.PrimaryContactPhone
                                    || dirPartyTable.PrimaryContactEmail == electronicAddress.RecId
                                    || dirPartyTable.PrimaryContactFax == electronicAddress.RecId

                                join logisticsLocation where logisticsLocation.RecId == dirPartyTable.PrimaryAddressLocation
                                    join postalAddress where postalAddress.Location == logisticsLocation.RecId

    {
    row++;

    cell = cells.item(row,1);
    cell.value(custtable.AccountNum);
    cell = cells.item(row, 2);
    cell.value(custtable.custgroup);
    cell = cells.item(row, 3);
    cell.value(dirPartyTable.name);
    cell = cells.item(row, 4);
    cell.value(custtable.currency);
    cell = cells.item(row, 5);
    cell.value(postalAddress.countryRegionId);
    cell = cells.item(row, 6);
    cell.value(postalAddress.Address);
    cell = cells.item(row, 7);
    cell.value(electronicAddress.Type);
    cell = cells.item(row, 8);
    cell.value(electronicAddress.locator);
    }

     application.visible(true);


}

No comments:

Post a Comment