Hi Guys,
I had success with the link that John provided but having trouble in getting this to import multiple SOs header and lines in one file. I have a customer PO number as the reference on the header and lines files for each SO that I need created but having trouble in creating the logic and X++.
Any examples on importing multiple sales orders in one text file would be useful.
Here is the job I used and had success with on importing one sales order, I need to modify this to import multiple sales orders now.
static void MultiSalesOrdersLineImport(Args _args)
{
SalesTable salesTable;
SalesLine salesLine;
InventDim inventDim;
container readcon,readcon1;
NumberSeq num;
CommaIo commaIo,commaIo1;
;
commaIo = new CommaIo(@'C:\Users\Sergi\Desktop\importFile\Lines.txt','r');
commaIo1 = new CommaIo(@'C:\Users\Sergi\Desktop\importFile\Header.txt','r');
commaIo.infieldDelimiter(',');
try
{
ttsbegin;
// Order header
salesTable.clear();
readcon1 = commaIo1.read();
salesTable.CustAccount = conpeek(readcon1,1);
salesTable.InvoiceAccount = conpeek(readcon1,1);
salesTable.CustomerRef = conpeek(readcon1,2);
salesTable.CurrencyCode = 'USD';
salesTable.LanguageId = 'en-us';
num = NumberSeq::newGetNum(SalesParameters::numRefSalesId());
salesTable.SalesId = num.num();
salesTable.initValue();//
salesTable.initFromCustTable();
if (salesTable.validateWrite())
{
salesTable.insert();
while(commaIo.status() == IO_Status::OK)
{
//Order line
readcon = commaIo.read();
salesLine.ItemId = conpeek(readcon,1);
salesLine.CurrencyCode = 'USD';
if(salesLine.ItemId == "0")
break;
inventDim.clear();
inventDim.InventSiteId ='A';
inventDim.InventLocationId = 'MAIN';
salesLine.clear();
salesLine.initValue();
salesLine.initFromSalesTable(salesTable);
salesLine.ItemId = conpeek(readcon,1);
salesLine.initFromInventTable(InventTable::find(conpeek(readcon,1)));
salesLine.InventDimId = InventDim::findOrCreate(inventDim).inventDimId;
salesLine.SalesQty = conpeek(readcon,2);
salesLine.RemainSalesPhysical = salesLine.SalesQty;
salesLine.SalesUnit = conpeek(readcon,3);
salesLine.QtyOrdered = salesLine.calcQtyOrdered();
salesLine.RemainInventPhysical = salesLine.QtyOrdered;
salesLine.setPriceDisc(InventDim::find(salesLine.InventDimId));
if (salesLine.validateWrite())
{
salesLine.insert();
}
else
throw error("Order line");
}
}
else
throw error("Order header");
ttscommit;
}
catch
{
error("Error!");
return;
}
info("Done!");
}