Customization - duplicate OrderDtl lines after Update method in BO

Hi Folks,

I have a customization that creates multiple OrderDtl records through the SalesOrderAdapter before performing the Update method. In every instance, the content of Rows[0] is set to the content of the last Row regardless of how many rows are in the dataset after the Update method is called. This was working, and now it’s not. Has anyone come across something like this before? The relevant part of the code is as follows:

int SONum = 0;
bool processError = false;
SalesOrderAdapter SO;
SO = new SalesOrderAdapter(this.oTrans);
SO.BOConnect();
this.oTrans.PushStatusText("Creating New Order", true);
try 
{
    SO.GetNewOrderHed();
    SO.SalesOrderData.Tables["OrderHed"].Rows[0]["CustNum"] = Convert.ToInt32(edvUD101.dataView[edvUD101.Row]["Number01"]);
    SO.SalesOrderData.Tables["OrderHed"].Rows[0]["OrderDate"] = Convert.ToDateTime(dteOrdDte.Value);
    SO.SalesOrderData.Tables["OrderHed"].Rows[0]["PONum"] = txtPO.Value.ToString();
        .
        .
        .
    SO.SalesOrderData.Tables["OrderHed"].Rows[0]["EdiOrder"] = true;
    this.oTrans.PushStatusText("Saving Order Header", true);
    SO.Update();
    SONum = Convert.ToInt32(SO.SalesOrderData.Tables["OrderHed"].Rows[0]["OrderNum"]);
    edvUD101A.dataView.Sort = "ChildKey1";
    for (int line = 0; line < edvUD101A.dataView.Count; line++) 
    {
        this.oTrans.PushStatusText("Creating Order Line " + (line + 1).ToString(), true);
        SO.GetNewOrderDtl(SONum);
        SO.SalesOrderData.Tables["OrderDtl"].Rows[line]["OrderLine"] = line + 1;
        SO.SalesOrderData.Tables["OrderDtl"].Rows[line]["DisplaySeq"] = line + 1;
        SO.SalesOrderData.Tables["OrderDtl"].Rows[line]["PartNum"] = edvUD101A.dataView[line]["ShortChar01"].ToString();
            .
            .
            .
        SO.SalesOrderData.Tables["OrderDtl"].Rows[line]["DemandContractNum"] = Convert.ToInt32(edvUD101A.dataView[line]["Number09"]);
        SO.SalesOrderData.Tables["OrderDtl"].Rows[line]["DemandContractLine"] = Convert.ToInt32(edvUD101A.dataView[line]["Number10"]);
    }
    this.oTrans.PushStatusText("Saving Order Lines", true);
    SO.Update();
}
catch (Exception ex)
{
    EpiMessageBox.Show(ex.Message, "Create Order Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    if (SONum > 0)
    {
        processError = true;
        SO.Dispose();
        SO = new SalesOrderAdapter(this.oTrans);
        SO.BOConnect();
        SO.GetByID(SONum);
        SO.SalesOrderData.Tables["OrderHed"].Rows[0].Delete();
        SO.Update();
    }
}
SO.Dispose();
SO = null;
this.oTrans.PushStatusText("Ready", false);

These are the OrderDtl record contents just before the Update method:

And these are the OrderDtl record contents just after the Update method. Note the first and last rows are identical other than the OrderLine column.

The other thing that is odd is that the trace shows that an Erp.Proxy.BO.SalesOrderImpl.Update occurs on its own in place of the Erp.Proxy.BO.SalesOrderImpl.GetNewOrderDtl ahead of the last detail line. I have no idea why that is happening, but I suspect that is the cause of the problem.

Almost looks like your sort may be playing tricks on you. That’s going to reorder the expected rows before you manipulate them.

I will comment that out and try again.

Nope, same results.

Also, for the sake of trying anything. I’d make sure to clear all adapter data after updating.

I do. I create the adapter object just before creating the OrderHed record and destroy it after the OrderDtl records are written.

I’m grasping for straws here. Do you debug in VS?

what about notifying your dataView of changes?

Have you tried CreatingSalesOrders and updating one at a time instead of in bulk?

It will work one line at a time, but it is slow when there are dozens of lines to insert. We turned UD101 and 101A into a quickie order entry so that large orders with single-release lines can be entered quickly…

I don’t debug in VS. Not Epicor at least.

I will try clearing the adapter after the header update in the morning. It can’t hurt to try.

1 Like

I wish you luck. I am hoping to learn something good from your struggles, keep us posted!

The problem is in the workflow of a BPM triggered by the SalesOrders.Update method. I’m copying the contents of ttOrderDtl added lines to another temporary table in order to verify certain criteria, rather than against the ttOrderDtl directly. Whether I write to a dataset variable I create in custom code, or utilize the Fill Table by Query setter into a local variable of the type SalesOrderTableset - as soon as that operation is performed, the row pointer on the ttOrderDtl table gets screwed up and the contents of the last line overwrite the first line. Anyone encounter this before?