I found some code that:
- show how to create a template in a method.
- demonstrate importing with excel using a method.
- show an export of data using excel via a method.
- demonstrate how you can update existing data in AX using excel via method
All you see below is copy/paste
with some cosmetic changes.
The first thing I will do is create a template in a method.
void createTemplate()
{
SysExcelApplication xlsApplication;
SysExcelWorkBooks xlsWorkBookCollection;
SysExcelWorkBook xlsWorkBook;
SysExcelWorkSheets xlsWorkSheetCollection;
SysExcelWorkSheet xlsWorkSheet;
SysExcelRange xlsRange;
CustTable custTable;
WfsRMCustAssignedRoute assignedRoute;
int row = 1;
str fileName;
;
//Filename
fileName = "C:\\Test.xlsx";
//Initialize Excel instance
xlsApplication = SysExcelApplication::construct();
//Open Excel document
//xlsApplication.visible(true);
//Create Excel WorkBook and WorkSheet
xlsWorkBookCollection = xlsApplication.workbooks();
xlsWorkBook = xlsWorkBookCollection.add();
xlsWorkSheetCollection = xlsWorkBook.worksheets();
xlsWorkSheet = xlsWorkSheetCollection.itemFromNum(1);
//Excel columns captions
xlsWorkSheet.cells().item(row,1).value("Item number");
// xlsWorkSheet.cells().item(row,2).value("Item name ");
xlsWorkSheet.cells().item(row,2).value("Quanitity");
xlsWorkSheet.cells().item(row,3).value("UM");
row++;
xlsWorkSheet.columns().autoFit();
//Check whether the document already exists
if(WinApi::fileExists(fileName))
WinApi::deleteFile(fileName);
//Save Excel document
// xlsWorkbook.saveAs(fileName);
//Open Excel document
xlsApplication.visible(true);
//Close Excel
//xlsApplication.quit();
//xlsApplication.finalize();
}
Next I will demonstrate importing with excel using a method
void importToExcel()
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
System.DateTime ShlefDate;
FilenameOpen filename;
dialogField dialogFilename;
Dialog dialog;
//Table Declarations Starts
WfsRMTruckPlanItems items;
WfsRMTruckPlanItems checkRoute;
//Table Declartions Ends
ItemId itemId;
ItemName itemName;
str qty;
UnitId unitId;
CustTable findCustTable;
str delSeq;
InventTable inventTable;
int row = 1;
#Excel
// convert into str from excel cell value
str COMVariant2Str(COMVariant _cv, int _decimals = 0, int _characters = 0, int _separator1 = 0, int _separator2 = 0)
{
switch (_cv.variantType())
{
case (COMVariantType::VT_BSTR):
return _cv.bStr();
case (COMVariantType::VT_R4):
return num2str(_cv.float(),_characters,_decimals,_separator1,_separator2);
case (COMVariantType::VT_R8):
return num2str(_cv.double(),_characters,_decimals,_separator1,_separator2);
case (COMVariantType::VT_DECIMAL):
return num2str(_cv.decimal(),_characters,_decimals,_separator1,_separator2);
case (COMVariantType::VT_DATE):
return date2str(_cv.date(),123,2,1,2,1,4);
case (COMVariantType::VT_EMPTY):
return "";
default:
throw error(strfmt("@SYS26908", _cv.variantType()));
}
return "";
}
;
ttsbegin;
delete_from checkRoute where checkRoute.TruckPlanVerId == WfsRMTruckPlanVer.TruckPlanVerId;
ttscommit;
info("Excel import template must be used with the following columns, A) Item number B) Quantity C) UM");
dialog = new Dialog("Upload Route plan items import file");
dialogFilename = dialog.addField(typeId(FilenameOpen));
dialog.filenameLookupFilter(["@SYS28576",#XLSX,"@SYS28576",#XLS]);
dialog.filenameLookupTitle("Route plan items import");
dialog.caption("Route plan items import");
dialogFilename.value(filename);
if(!dialog.run())
return;
filename = dialogFilename.value();
application = SysExcelApplication::construct();
workbooks = application.workbooks();
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened.");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
try
{
ttsbegin;
do
{
row++;
ItemId = COMVariant2Str(cells.item(row, 1).value());
// ItemName = COMVariant2Str(cells.item(row,2).value());
Qty = COMVariant2str(cells.item(row, 2).value());
UnitId = COMVariant2Str(cells.item(row, 3).value());
if(row > 1)
{
if(InventTable::find(itemId))
{
items.clear();
items.selectForUpdate();
items.ItemId = itemId;
items.Qty = str2num(qty);
items.UnitId = unitId;
items.TruckPlanVerId = WfsRMTruckPlanVer.TruckPlanVerId;
items.insert();
}
}
type = cells.item(row+1, 1).value().variantType();
}while (type != COMVariantType::VT_EMPTY);
application.quit();
ttscommit;
}
catch
{
Error("Import Failed");
}
}
------------------------------------------------------------------------------------
Next I will show an export of data using excel via a method
void exportToExcel()
{
CustTable custTable;
SysExcelApplication application;
SysExcelWorkBooks workbooks;
SysExcelWorkBook workbook;
SysExcelWorksheets worksheets;
sysExcelWorksheet worksheet;
SysExcelCells cells;
SysExcelCell cell;
int row;
WfsCSWalkupCustInfo custInfo;
;
application = SysExcelApplication::construct();
workbooks = application.workbooks(); //gets the workbook object
workbook = workbooks.add(); // creates a new workbook
worksheets = workbook.worksheets(); //gets the worksheets object
worksheet = worksheets.itemFromNum(1);//Selects the first worksheet in the workbook to insert data
cells = worksheet.cells();
cells.range('A:A').numberFormat('@'); // numberFormat ‘@’ is to insert data as Text
while select custInfo
//The following loop will provide the data to be populated in each column
{
row++;
cell = cells.item(row,1);
cell.value(custInfo.CompanyName);
cell = cells.item(row,2);
cell.value(custInfo.FirstName);
cell = cells.item(row,3);
cell.value(custInfo.LastName);
cell = cells.item(row,4);
cell.value(custInfo.Phone);
cell = cells.item(row,5);
cell.value(custInfo.Email);
cell = cells.item(row,6);
cell.value(custInfo.Street);
cell = cells.item(row,7);
cell.value(custInfo.StateId);
cell = cells.item(row,8);
cell.value(custInfo.City);
cell = cells.item(row,9);
cell.value(custInfo.Country);
cell = cells.item(row,10);
cell.value(custInfo.ZipCodeId);
}
application.visible(true); // opens the excel worksheet
}
----------------------------------------------
Now I will demonstrate how you can update existing data in AX using excel via method
static void WfsRMUpdateCustomers(Args _args)
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
System.DateTime ShlefDate;
FilenameOpen filename;
dialogField dialogFilename;
Dialog dialog;
wfsRMParameters parms = wfsRMParameters::find();
FileIOPermission fioPermission;
str filename2 = "CustomerUpdateErrorLog" + strltrim(date2str(systemdateget(),213,1,1,2,1,4))+".txt";// "C:\\Users\\dstevenson\testing.txt";
str sTempPath;
Args args = new args();
wfsRMPickListSummary lines;
ReportRun reportRun;
//"C:\\Users\\dstevenson\\CustomerUpdateErrorLog" + date2str(systemdateget(),213,2,4,2,4,4)+".txt";
AsciiIo txIoRead,
txIoWrite;
// txIoWrite = new TextIo( sTempPath + sFileName ,"W");
//Table Declarations Starts
CustTable custTable;
AddressCountryRegion AddressCountryRegion;
AddressState AddressState;
AddressZipCode AddressZipCode;
AddressCounty AddressCounty;
CustGroup custGroupTbl;
smmBusRelSegmentGroup smmBusRelSegmentGroup;
smmBusRelSubSegmentGroup smmBusRelSubSegmentGroup;
LineOfBusiness LineOfBusiness;
CustStatisticsGroup CustStatisticsGroup;
CustClassificationGroup CustClassificationGroup;
WfsCustSICCode WfsCustSICCode;
WfsCustNaicsCode WfsCustNaicsCode;
WfsCustClassification1 WfsCustClassification1;
WfsCustClassification2 WfsCustClassification2;
WfsCustClassification3 WfsCustClassification3;
WfsCustClassification4 WfsCustClassification4;
WfsCustClassification5 WfsCustClassification5;
wfsArea wfsArea;
wfsRegion wfsRegion;
DirPartyTable DirPartyTable;
Address Address;
wfsRMRouteTable routeTable;
wfsRMCustomerUpdateErrorLog wfsRMCustomerUpdateErrorLog;
//Table Declartions Ends
custAccount custAccount;
Addressing addressing;
AddressStateId state;
AddressCountyId county;
AddressCity city;
AddressZipCodeId zip;
AddressCountryRegionId country;
smmSegmentId segment;
smmSubsegmentId subSegment;
CustGroupId custGroup;
CustLineOfBusinessId lineOfBusinessID;
CustClassificationId channel;
CustStatGroupId stats;
WfsCustSicCodeID sicCodeId;
str NAICS;
WfsCustClassification1Id cust1;
WfsCustClassification2Id cust2;
WfsCustClassification3Id cust3;
WfsCustClassification4Id cust4;
WfsCustClassification5Id cust5;
wfsAreaId area;
wfsRegionId region;
wfsRMRouteId route;
CustAccount oldCustomer;
EmplId tradeMarketingRep;
EmplId salesRep;
str delSeq;
InventTable inventTable;
int row = 1;
Counter x = 0, y = 0;
boolean ret = true;
#Excel
// convert into str from excel cell value
str COMVariant2Str(COMVariant _cv, int _decimals = 0, int _characters = 0, int _separator1 = 0, int _separator2 = 0)
{
switch (_cv.variantType())
{
case (COMVariantType::VT_BSTR):
return _cv.bStr();
case (COMVariantType::VT_R4):
return num2str(_cv.float(),_characters,_decimals,_separator1,_separator2);
case (COMVariantType::VT_R8):
return num2str(_cv.double(),_characters,_decimals,_separator1,_separator2);
case (COMVariantType::VT_DECIMAL):
return num2str(_cv.decimal(),_characters,_decimals,_separator1,_separator2);
case (COMVariantType::VT_DATE):
return date2str(_cv.date(),123,2,1,2,1,4);
case (COMVariantType::VT_EMPTY):
return "";
default:
throw error(strfmt("@SYS26908", _cv.variantType()));
}
return "";
}
;
// info("Excel import template must be used with the following columns, A) Item number B) Quantity C) UM");
dialog = new Dialog("Update customer table from excel spreadsheet");
dialogFilename = dialog.addField(typeId(FilenameOpen));
dialog.filenameLookupFilter(["@SYS28576",#XLSX,"@SYS28576",#XLS]);
dialog.filenameLookupTitle("Customer update file");
dialog.caption("Customer update");
dialogFilename.value(filename);
if(!dialog.run())
return;
filename = dialogFilename.value();
application = SysExcelApplication::construct();
workbooks = application.workbooks();
fioPermission = new FileIOPermission
(filename2 ,"RW");
fioPermission.assert();
sTempPath = parms.CustomerImportFileName;//WINAPI::getTempPath();
// sTempPath = WINAPI::getTempPath();
txIoWrite = new AsciiIo( sTempPath + filename2 ,"W");
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened.");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
try
{
ttsbegin;
do
{
row++;
ret = true;
custAccount = COMVariant2Str(cells.item(row, 1).value());
addressing = COMVariant2Str(cells.item(row, 2).value());
city = COMVariant2str(cells.item(row, 3).value());
State = COMVariant2Str(cells.item(row, 4).value());
Zip = COMVariant2Str(cells.item(row, 5).value());
country = COMVariant2Str(cells.item(row, 6).value());
segment = COMVariant2Str(cells.item(row, 7).value());
subSegment = COMVariant2Str(cells.item(row, 8).value());
custGroup = COMVariant2Str(cells.item(row, 9).value());
channel = COMVariant2Str(cells.item(row, 10).value());
stats = COMVariant2Str(cells.item(row, 11).value());
lineOfBusinessId = COMVariant2Str(cells.item(row, 12).value());
sicCodeId = COMVariant2Str(cells.item(row, 13).value());
NAICS = COMVariant2Str(cells.item(row, 14).value());
cust1 = COMVariant2Str(cells.item(row, 15).value());
cust2 = COMVariant2Str(cells.item(row, 16).value());
cust3 = COMVariant2Str(cells.item(row, 17).value());
cust4 = COMVariant2Str(cells.item(row, 18).value());
cust5 = COMVariant2Str(cells.item(row, 19).value());
area = COMVariant2Str(cells.item(row, 20).value());
region = COMVariant2Str(cells.item(row, 21).value());
route = COMVariant2Str(cells.item(row, 22).value());
oldCustomer = COMVariant2Str(cells.item(row, 23).value());
tradeMarketingRep = COMVariant2Str(cells.item(row, 24).value());
salesRep = COMVariant2Str(cells.item(row, 25).value());
if(row > 1)
{
custTable = custTable::find(custAccount,true);
if(!custTable && oldCustomer)
{
select firstonly forupdate custTable where custTable.WfsOldAccountNum == oldCustomer;
}
DirPartyTable = DirPartyTable::find(custTable.PartyId);
Address = Address::find(DirPartyTable.TableId,DirPartyTable.RecId,AddressType::Invoice,true);
if(custTable)
{
if(address)
{
if(addressing && ret)
{
address.Street = addressing;
}
if(city && ret)
{
address.City = city;
}
if(state && country && ret)
{
AddressCountryRegion = AddressCountryRegion::find(country);
AddressState = AddressState::find(country,state);
if(AddressState && AddressCountryRegion)
{
address.CountryRegionId = country;
address.State = state;
}
else
{
ret = false;
wfsRMCustomerUpdateErrorLog.clear();
wfsRMCustomerUpdateErrorLog.CustAccount = custAccount;
wfsRMCustomerUpdateErrorLog.OldCustAcct = oldCustomer;
wfsRMCustomerUpdateErrorLog.State = state;
wfsRMCustomerUpdateErrorLog.Country = country;
wfsRMCustomerUpdateErrorLog.insert();
y++;
}
}
if(AddressCountryRegion && country && ret == true)
{
address.CountryRegionId = country;
}
AddressZipCode = AddressZipCode::find(zip);
if(AddressZipCode && zip && ret == true)
{
Address.ZipCode = zip;
}
else
{
if(zip && !AddressZipCode)
{
ret = false;
wfsRMCustomerUpdateErrorLog.clear();
wfsRMCustomerUpdateErrorLog.CustAccount = custAccount;
wfsRMCustomerUpdateErrorLog.OldCustAcct = oldCustomer;
wfsRMCustomerUpdateErrorLog.ZipCode = zip;
wfsRMCustomerUpdateErrorLog.insert();
y++;
//continue;
}
}
AddressCounty = AddressCounty::find(country,state,county);
if(AddressCounty && county && ret)
{
if(county)
{
address.County = county;
}
else
{
ret = false;
wfsRMCustomerUpdateErrorLog.clear();
wfsRMCustomerUpdateErrorLog.CustAccount = custAccount;
wfsRMCustomerUpdateErrorLog.County = county;
wfsRMCustomerUpdateErrorLog.insert();
y++;
// continue;
}
}
if(ret)
{
address.Address = address::formatAddress(address.Street,address.ZipCode,address.City,
address.CountryRegionId,address.State,address.County);
address.update();
}
}
//Attributes
if(segment)
{
smmBusRelSegmentGroup = smmBusRelSegmentGroup::find(segment);
if(smmBusRelSegmentGroup && segment && ret)
{
custTable.SegmentId = segment;
}
else
{
ret = false;
wfsRMCustomerUpdateErrorLog.clear();
wfsRMCustomerUpdateErrorLog.CustAccount = custAccount;
wfsRMCustomerUpdateErrorLog.OldCustAcct = oldCustomer;
wfsRMCustomerUpdateErrorLog.segment = segment;
wfsRMCustomerUpdateErrorLog.insert();
y++;
// continue;
}
}
if(subSegment)
{
select firstonly smmBusRelSubSegmentGroup where smmBusRelSubSegmentGroup.SubsegmentId == subsegment &&
smmBusRelSubSegmentGroup.SegmentId == segment;
if( smmBusRelSubSegmentGroup && ret)
{
custTable.SubsegmentId = subsegment;
}
else
{
ret = false;
wfsRMCustomerUpdateErrorLog.clear();
wfsRMCustomerUpdateErrorLog.CustAccount = custAccount;
wfsRMCustomerUpdateErrorLog.Subsegment = subSegment;
wfsRMCustomerUpdateErrorLog.insert();
y++;
}
}
if(lineofBusinessId && ret)
{
LineOfBusiness = LineOfBusiness::find(lineOfBusinessId);
if(LineOfBusiness)
{
custTable.LineOfBusinessId = lineofBusinessId;
}
else
{
ret = false;
wfsRMCustomerUpdateErrorLog.clear();
wfsRMCustomerUpdateErrorLog.CustAccount = custAccount;
wfsRMCustomerUpdateErrorLog.LineOfBusiness = LineOfBusinessId;
wfsRMCustomerUpdateErrorLog.OldCustAcct = oldCustomer;
wfsRMCustomerUpdateErrorLog.insert();
y++;
}
}
if(stats && ret)
{
CustStatisticsGroup = CustStatisticsGroup::find(stats);
if(CustStatisticsGroup)
{
custTable.StatisticsGroup = stats;
}
else
{
wfsRMCustomerUpdateErrorLog.clear();
wfsRMCustomerUpdateErrorLog.CustAccount = custAccount;
wfsRMCustomerUpdateErrorLog.SalesLocation = stats;
wfsRMCustomerUpdateErrorLog.OldCustAcct = oldCustomer;
wfsRMCustomerUpdateErrorLog.insert();
y++;
// continue;
}
}
if(channel && ret)
{
custTable.CustClassificationId = channel;
}
if(SicCodeId && ret)
{
WfsCustSICCode = WfsCustSICCode::find(sicCodeId);
if(WfsCustSICCode)
{
custTable.WfsSicCodeID = sicCodeId;
}
else
{
ret = false;
wfsRMCustomerUpdateErrorLog.clear();
wfsRMCustomerUpdateErrorLog.CustAccount = custAccount;
wfsRMCustomerUpdateErrorLog.SICCodeId = sicCodeId;
wfsRMCustomerUpdateErrorLog.OldCustAcct = oldCustomer;
wfsRMCustomerUpdateErrorLog.insert();
y++;
//continue;
}
}
if(NAICS && ret)
{
WfsCustNaicsCode = WfsCustNaicsCode::find(naics);
if(WfsCustNaicsCode)
{
custTable.WfsNaicsCode = naics;
}
else
{
ret = false;
wfsRMCustomerUpdateErrorLog.clear();
wfsRMCustomerUpdateErrorLog.CustAccount = custAccount;
wfsRMCustomerUpdateErrorLog.NACISCode = naics;
wfsRMCustomerUpdateErrorLog.OldCustAcct = oldCustomer;
wfsRMCustomerUpdateErrorLog.insert();
y++;
}
}
if(cust1 && ret)
{
select firstonly WfsCustClassification1 where WfsCustClassification1.Classification1 == cust1;
if(cust1)
{
custTable.WfsCustClassification1Id = cust1;
}
else
{
ret = false;
wfsRMCustomerUpdateErrorLog.clear();
wfsRMCustomerUpdateErrorLog.CustAccount = custAccount;
wfsRMCustomerUpdateErrorLog.Class1 = cust1;
wfsRMCustomerUpdateErrorLog.OldCustAcct = oldCustomer;
wfsRMCustomerUpdateErrorLog.insert();
y++;
}
}
if(cust2 && ret)
{
select firstonly WfsCustClassification2 where WfsCustClassification2.Classification2 == cust2;
if(cust2)
{
custTable.WfsCustClassification2Id = cust2;
}
else
{
ret = false;
wfsRMCustomerUpdateErrorLog.clear();
wfsRMCustomerUpdateErrorLog.CustAccount = custAccount;
wfsRMCustomerUpdateErrorLog.Premise = cust2;
wfsRMCustomerUpdateErrorLog.OldCustAcct = oldCustomer;
wfsRMCustomerUpdateErrorLog.insert();
y++;
}
}
if(cust3 && ret )
{
select firstonly WfsCustClassification3 where WfsCustClassification3.Classification3 == cust3;
if(cust3)
{
custTable.WfsCustClassification3Id = cust3;
}
else
{
ret = false;
wfsRMCustomerUpdateErrorLog.clear();
wfsRMCustomerUpdateErrorLog.CustAccount = custAccount;
wfsRMCustomerUpdateErrorLog.OldCustAcct = oldCustomer;
wfsRMCustomerUpdateErrorLog.AccountType = cust3;
wfsRMCustomerUpdateErrorLog.insert();
y++;
}
}
if(cust4 && ret)
{
select firstonly WfsCustClassification4 where WfsCustClassification4.Classification4 == cust4;
if(cust4)
{
custTable.WfsCustClassification4Id = cust4;
}
else
{
ret = false;
wfsRMCustomerUpdateErrorLog.clear();
wfsRMCustomerUpdateErrorLog.CustAccount = custAccount;
wfsRMCustomerUpdateErrorLog.Class4 = cust4;
wfsRMCustomerUpdateErrorLog.OldCustAcct = oldCustomer;
wfsRMCustomerUpdateErrorLog.insert();
y++;
// continue;
}
}
if(cust5 && ret)
{
select firstonly WfsCustClassification5 where WfsCustClassification5.Classification5 == cust5;
if(cust5)
{
custTable.WfsCustClassification5Id = cust5;
}
else
{
ret = false;
wfsRMCustomerUpdateErrorLog.clear();
wfsRMCustomerUpdateErrorLog.CustAccount = custAccount;
wfsRMCustomerUpdateErrorLog.Class5 = cust5;
wfsRMCustomerUpdateErrorLog.OldCustAcct = oldCustomer;
wfsRMCustomerUpdateErrorLog.insert();
y++;
}
}
if(area && ret)
{
wfsArea = wfsArea::find(area);
if(wfsArea)
{
custTable.wfsAreaId = area;
}
else
{
ret = false;
wfsRMCustomerUpdateErrorLog.clear();
wfsRMCustomerUpdateErrorLog.CustAccount = custAccount;
wfsRMCustomerUpdateErrorLog.Area = area;
wfsRMCustomerUpdateErrorLog.OldCustAcct = oldCustomer;
wfsRMCustomerUpdateErrorLog.insert();
y++;
}
}
if(region && area && ret)
{
wfsRegion = wfsREgion::find(region,area);
if(wfsRegion)
{
custTable.wfsRegionId = region;
}
else
{
ret = false;
wfsRMCustomerUpdateErrorLog.clear();
wfsRMCustomerUpdateErrorLog.CustAccount = custAccount;
wfsRMCustomerUpdateErrorLog.Region = region;
wfsRMCustomerUpdateErrorLog.OldCustAcct = oldCustomer;
wfsRMCustomerUpdateErrorLog.insert();
y++;
}
}
if(route)
{
routeTable = wfsRMRouteTable::find(route);
}
if(tradeMarketingRep)
{
if(EmplTable::find(tradeMarketingRep))
{
custTable.wfsRMTradeMarketingRep = tradeMarketingRep;
}
else
{
ret = false;
wfsRMCustomerUpdateErrorLog.clear();
wfsRMCustomerUpdateErrorLog.CustAccount = custAccount;
wfsRMCustomerUpdateErrorLog.TradeMarketRep = tradeMarketingRep;
wfsRMCustomerUpdateErrorLog.OldCustAcct = oldCustomer;
wfsRMCustomerUpdateErrorLog.insert();
y++;
}
}
if(salesRep)
{
if(EmplTable::find(salesRep))
{
custTable.wfsRMTradeMarketingRep = salesRep;
}
else
{
ret = false;
wfsRMCustomerUpdateErrorLog.clear();
wfsRMCustomerUpdateErrorLog.CustAccount = custAccount;
wfsRMCustomerUpdateErrorLog.SalesRep = salesRep;
wfsRMCustomerUpdateErrorLog.OldCustAcct = oldCustomer;
wfsRMCustomerUpdateErrorLog.insert();
y++;
}
}
if(ret)
{
custTable.update();
x++;
}
}
else
{
ret = false;
wfsRMCustomerUpdateErrorLog.clear();
wfsRMCustomerUpdateErrorLog.CustAccount = custAccount;
wfsRMCustomerUpdateErrorLog.OldCustAcct = oldCustomer;
wfsRMCustomerUpdateErrorLog.insert();
y++;
}
}
if(oldCustomer && !custAccount)
{
type = cells.item(row+1, 23).value().variantType();
}
if(!oldCustomer && custAccount)
{
type = cells.item(row+1, 1).value().variantType();
}
}
while (type != COMVariantType::VT_EMPTY);
application.quit();
ttscommit;
if(wfsRMCustomerUpdateErrorLog)
{
args = new Args();
args.name(reportStr(wfsRMCustomerUpdateImportErrorLog));
args.record(wfsRMCustomerUpdateErrorLog);
reportRun = classfactory.reportRunClass(args);
reportRun.init();
reportRun.run();
}
info(int2str(x) + " " + "customer record(s) updated successfully." + " " + int2str(y) + " " + "customer record(s) have errors.");
}
catch
{
Error("Import Failed");
}
}
———————————————-—————————————–
Found here: http://www.winfosoft.com/blog/microsoft-dynamics-ax/data-importing-and-exporting-using-excel