X++ code to create CustVendExternalItem from csv import in Microsoft Dynmics AX 2012 R3
static void RB_ExternalItemImport(Args _args)
{
#File
IO iO;
FilenameOpen filename = "c:\\ExternalItem.csv";//file name here
CustVendExternalItem CustVendExternalItem;
InventTable inventTable;
VendTable vendTable;
VendAccount supplierId;
ItemId itemId;
ExternalItemId ExternalItemId;
Container con;
boolean first = true;
FileIoPermission perm;
int created,error;
InventDim inventDim = InventDim::find('AllBlank');
iO = new CommaTextIo(filename,#IO_Read);
if (! iO || iO.status() != IO_Status::Ok)
{
throw error("@SYS19358");
}
while (iO.status() == IO_Status::Ok)
{
con = iO.read();// read file
if (con)
{
if (first) //skip header
{
first = false;
}
else
{
supplierId = conPeek(con,1);
ItemId = conPeek(con,2);
ExternalItemId = conPeek(con,3);
inventTable = inventTable::find(ItemId);
VendTable = VendTable::find(supplierId);
if (inventTable && VendTable)
{
CustVendExternalItem.clear();
CustVendExternalItem.initValue();
CustVendExternalItem.ABCCategory = ABC::None;
CustVendExternalItem.CustVendRelation = supplierId;
CustVendExternalItem.ExternalItemId = ExternalItemId;
CustVendExternalItem.ItemId = inventTable.ItemId;
CustVendExternalItem.InventDimId = inventDim.inventdimid;
CustVendExternalItem.ModuleType = ModuleInventPurchSalesVendCustGroup::Vend;
CustVendExternalItem.insert();
created++;
}
else
{
error++;
info(strFmt("%1,%2 not created", ItemId, supplierId));
}
}
}
}
info("Mission Accomplished");
}
No comments:
Post a Comment