Trying to update Customer from CustCnt.Update post-processing BPM

I need to update a UD field on the Customer table if/when a user edits a customer contact in a particular way. A pre-processing BPM on CustCnt.Update flags when this needs to happen by setting one of the callContextBpmData checkboxes to true, so that my post-processing BPM only fires when it needs to.

In the post proc I try updating Customer as such:


foreach (var custCntRow in ttCustCnt)
{
  if (this.callContextBpmData.Checkbox08)
  {
    this.callContextBpmData.Checkbox08 = false;
    int custNum = custCntRow.CustNum;
    bool reqAuthBuyers = Db.CustCnt.Any(cc => cc.Company == custCntRow.Company
                  && cc.CustNum == custNum
                  && cc.CheckBox06);
   
    var custSVC = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.CustomerSvcContract>(this.Db);

    using (custSVC)
    {
       CustomerTableset custDS = custSVC.GetByID(custNum);
       var customerRow = custDS.Customer.Where(c => c.CustNum == custNum).FirstOrDefault();

        if (customerRow != null)
        {
            customerRow["CheckBox07"] = reqAuthBuyers;
            customerRow.RowMod = "U";
            custSVC.Update(ref custDS);
        }
    }
  }
}

At runtime I get a Server Side Exception when the code tries to execute the update bit

Inside the server logs I see this:

I cannot figure out what I’m doing wrong here. I am only updating, not adding new records, so I have no idea why an insertion is trying to happen on CustAttr.

Is the Customer BO just really weird behind the scenes? Am I missing something obvious?

Figured it out thanks to @josecgomez in this post:

Here’s the working code:


foreach (var custCntRow in ttCustCnt)
{
  if (this.callContextBpmData.Checkbox08)
  {
    this.callContextBpmData.Checkbox08 = false;
   
    int custNum = custCntRow.CustNum;

    bool reqAuthBuyers = Db.CustCnt.Any(cc => cc.Company == custCntRow.Company

                  && cc.CustNum == custNum

                  && cc.CheckBox06);
   
    var custSVC = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.CustomerSvcContract>(this.Db);
    using (custSVC)
    {
       CustomerTableset custDS = custSVC.GetByID(custNum);
       var custNew = (CustomerRow)custDS.Customer.NewRow();
       BufferCopy.Copy(custDS.Customer[0], custNew);
       custNew["CheckBox07"] = reqAuthBuyers;
       custNew.RowMod = "U";
      
       custDS.Customer.Add(custNew);      

       custSVC.Update(ref custDS);
    }

   
    // using this to trigger an oTrans.Refresh() in customization

    this.callContextBpmData.Checkbox09 = true;  
  }
}