Hey there,
I’d appreciate a second pair of eyes or 100. In the code below I’m reading from records in UD09 of selected BTO Drop-Ship order releases, with the intent of creating a purchase order for each site/order num.
At this present early stage, it would create a PO for each order release.
A single record works great–sets up the header record and the detail.
But when I add the second UD09 record, it sets up the first PO okay, creates the second PO header and dies on the update. I’ve tried creating a new tableset, without any evident effect.
I can’t see the issue. Have some fresh eyes you’d care to lend?
Thanks,
Joe
// process POs
Erp.Contracts.POSvcContract poEntry = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.POSvcContract>(this.Db, true);
using(var txscope = IceDataContext.CreateDefaultTransactionScope()) //Start Transaction
{
foreach(var ttUD09_xRow in (from row in ttUD09
select row))
{
if (Convert.ToDecimal(ttUD09_xRow["NewPOQty_c"]) >0)
{
//tried creating new tableset each time
//dsPO = new Erp.Tablesets.POTableset();
poEntry.GetNewPOHeader(ref dsPO);
var poHeader_xRow = (from row in dsPO.POHeader
where row.RowMod == IceRow.ROWSTATE_ADDED
select row).FirstOrDefault();
bool poHeaderUpdated = false;
if (poHeader_xRow != null)
{
poHeader_xRow.OpenOrder = true;
poHeader_xRow.OrderDate = DateTime.Now;
poHeader_xRow.VendorNum = Convert.ToInt32(ttUD09_xRow["VendorNum_c"]);
poHeader_xRow.BuyerID = "1000";
poHeader_xRow.TermsCode = "T100";
poHeader_xRow.ShipViaCode = "BW";
poHeader_xRow.ReadyToPrint = true;
poHeader_xRow.Approve = false;
poHeader_xRow.POType = "STD";
poHeaderUpdated = true;
}
if (poHeaderUpdated)
{
//dies right here on the second PO
poEntry.Update(ref dsPO);
poHeader_xRow = (from row in dsPO.POHeader
select row).FirstOrDefault();
if (poHeader_xRow != null)
{
bool poDetailUpdated = false;
poEntry.GetNewPODetail(ref dsPO, poHeader_xRow.PONum);
var poDetail_xRow = (from row in dsPO.PODetail
where row.RowMod == IceRow.ROWSTATE_ADDED
select row).FirstOrDefault();
if (poDetail_xRow != null)
{
poEntry.ChangeDetailOrderNum(Convert.ToInt32(ttUD09_xRow["OrderNum_c"]), ref dsPO);
poEntry.ChangeDetailOrderLine(Convert.ToInt32(ttUD09_xRow["OrderLine_c"]), ref dsPO);
poDetailUpdated = true;
}
if (poDetailUpdated) poEntry.Update(ref dsPO);
}
}
//ttUD09_xRow.RowMod = "D";
}
}
txscope.Complete(); //Close Transaction
}