Updating RcvDtl from UBAQ BPM CustomCode

Hi All,

Can anyone tell me why this isn’t working?

Erp.Tables.RcvDtl RcvDtl;

foreach (var tt in ttResults.Where(tt => tt.Updated() || tt.Added()))
{
  RcvDtl = (from rd in Db.RcvDtl.With(LockHint.UpdLock) where 
         rd.Company == callContextClient.CurrentCompany && 
         rd.PONum == poNum &&
         rd.PackSlip == packSlip &&
         rd.VendorNum == tt.RcvDtl_VendorNum &&
         rd.PurPoint == tt.RcvDtl_PurPoint
         
         select rd).FirstOrDefault();
  
  if(RcvDtl!=null) 
  {
   
    RcvDtl["SubConProcd_c"] = vProcessed;
    
    Db.Validate();
  }
}

It’s currently on a CustomCode block on a UBAQ - GetList Post Processing :confused:

I would suggest putting some things in here to debug with. Either in the Ice logs or in a trace How to write your own trace logs - #2 by hmwillett

I’m wondering if your ttResults data is looping over anything with the where criteria. Second gut would be method

Checked all of that I can’t seem to get it to work with the method…

Few thins in a GetList POST there will be no Updated or Added records. Just use ttResults.ToList() and the second I am not sure if callContextClient.CurrentCompany would be populated, I would recommend using ttResults.Company

1 Like

Hi Haso,

Unfortunately, that didn’t work :frowning:

Not sure why is this a massive problem? I’m struggling with this one

Erp.Tables.RcvDtl RcvDtl;

foreach (var tt in ttResults.ToList())
{
try
    {
      using (var txscope1 = IceDataContext.CreateDefaultTransactionScope())
        {
            RcvDtl = (from rd in Db.RcvDtl.With(LockHint.UpdLock) where 
                   rd.Company == "TEAGLE" && 
                   rd.PONum == poNum &&
                   rd.PackSlip == packSlip &&
                   rd.VendorNum == vendorNum &&
                   rd.PurPoint == purPoint
                     select rd).FirstOrDefault();
  
          if(RcvDtl!=null) 
            {
              RcvDtl["SubConProcd_c"] = vProcessed;
              Db.Validate();
              }
         }     
    }
    catch (Exception ex)
       {
            Epicor.Hosting.Trace.ServerLog.WriteNonOperationException(ex);
            throw ex;
       }
}

Either use a event log entry or bpm msgbox to sus out the situation.

First how many records do this contain? ttResults.Where(tt => tt.Updated() || tt.Added()))
If that is as expected I’d do the same to determine if RcvDtl is null
Finally, log what vProcessed is per loop

(Also dont forget to look at any RcvDtl data directives that could be interferring)

Event logs are telling me absolutely nothing.

Here is the full code snippet, it’s some how skipping the RcvDtl section.

    bool brequiresUserInput = false;
        string spcMsg = "";
        int piMsgType = 0;
        string pcPCBinAction = "";
        string pcPCBinMessage = "";
        decimal pdSerialNoQty = 0;
        bool bplNegQtyAction = true;
        string pcMessage = "";
        string pcPartTranPKs = "";
        string pcProcessID = "RcptToInvEntry";
        //decimal dLaborQty = (r.RcvDtl_OurQty);
        string errorMsg = "";
        //string strWarehouseCode = (r.RcvDtl_WareHouseCode);
        //string strBinNum = (r.RcvDtl_BinNum);
        //string strJobNum = (r.JobOper_JobNum);
        int iAsmbSeq = 0;
        string tranReference = "UBAQ Auto Receipt for PUR-SUB";
        string lotNum = "";
        //string strLaborQty = "0";
        //int poNum = (r.RcvHead_PONum);
        int key1Num = new Random().Next(1000, 9999);  
        string strCompany = Session.CompanyID;

     try
      {
      
        using(var jobRcpttoInv = Ice.Assemblies.ServiceRenderer.GetService<ReceiptsFromMfgSvcContract>(Db))
        {
        
          ReceiptsFromMfgTableset RcptfrMfgDS = new ReceiptsFromMfgTableset();
          jobRcpttoInv.GetNewReceiptsFromMfgJobAsm(jobNum,0,"MFG-STK","RcptToInvEntry",ref RcptfrMfgDS);
          
          //RcptfrMfgDS.Tables["PartTran"].Rows[0]["Company"] = Session.CompanyID;
          RcptfrMfgDS.PartTran[0].Company = Session.CompanyID;
          RcptfrMfgDS.PartTran[0].WareHouseCode = warehouseCode;         
          jobRcpttoInv.OnChangeWareHouseCode(pcProcessID, ref RcptfrMfgDS);
          RcptfrMfgDS.PartTran[0].ActTranQty = tranQty;
          RcptfrMfgDS.PartTran[0].RowMod = "U";
          jobRcpttoInv.OnChangeActTranQty(ref RcptfrMfgDS,out spcMsg);           
          RcptfrMfgDS.PartTran[0].BinNum = binNum;
          RcptfrMfgDS.PartTran[0].ActTranQty = tranQty;          
          jobRcpttoInv.PreUpdate(ref RcptfrMfgDS, out brequiresUserInput);         
          RcptfrMfgDS.PartTran[0].TranQty = tranQty;
          RcptfrMfgDS.PartTran[0].ThisTranQty = tranQty;
          RcptfrMfgDS.PartTran[0].TranReference = Convert.ToString(key1Num);
          RcptfrMfgDS.PartTran[0].LotNum = "";
          jobRcpttoInv.VerifySerialMatchAndPlanContract(ref RcptfrMfgDS,out spcMsg,out piMsgType,out pcPCBinAction,out pcPCBinMessage);
          jobRcpttoInv.ReceiveMfgPartToInventory(ref RcptfrMfgDS,pdSerialNoQty,bplNegQtyAction,out pcMessage,out pcPartTranPKs,pcProcessID);
          } 
      }
      catch (Exception ex)
      {
         Ice.Diagnostics.Log.WriteEntry(ex.Message);
      }
      
  try
    {
      using (var txscope1 = IceDataContext.CreateDefaultTransactionScope())
        {
          var rcvDtl = Db.RcvDtl.Where(p=> 
                          p.Company == strCompany
                          && p.VendorNum == vendorNum
                          && p.PONum == poNum
                          && p.PackSlip == packSlip
                          && p.PurPoint == purPoint
                          && p.PackLine == packLine
                          && p.PartNum == partNum
                          ).FirstOrDefault();
          
         if(rcvDtl != null)
          {
            rcvDtl.SubConProcd_c =  vProcessed;
          
          }
          Db.Validate();
          txscope1.Complete();
        }
       } 
       catch (Exception exDtl)
       {
          Ice.Diagnostics.Log.WriteEntry(exDtl.Message);
       }
       
        using (var txScope = IceContext.CreateDefaultTransactionScope())
        {
          UD14 newRow = new UD14();
          Db.UD14.Insert(newRow);
          newRow.Company = Session.CompanyID;
          newRow.Key1 = Convert.ToString(key1Num);
          newRow.Key2 = Convert.ToString(poNum);
          newRow.Key3 = jobNum ;
          newRow.Key4 = "";
          newRow.Character01 = "AutoReceipt of PO: " + poNum + " Number";
          newRow.CheckBox01 = true; // or false
          Db.Validate();
          txScope.Complete();
        }    

vProcessed is just a string with the word Processed and there is currently only one row on the BAQ… :face_with_diagonal_mouth:

I just had a look into RcvDtl Data Directives and I cannot see any what would be blocking as there isn’t any :confused:

var candidates = Db.RcvDtl.Where(p=>
p.Company == strCompany
&& p.VendorNum == vendorNum
&& p.PONum == poNum
&& p.PackSlip == packSlip
&& p.PurPoint == purPoint
&& p.PackLine == packLine
&& p.PartNum == partNum
);
Ice.Diagnostics.Log.WriteEntry(candidates.Count());

What does that log?

It’s resolved now, I had a quick chat with Haso…

I did have a BPM Data Directive set to “Changed Rows” and it was instantly changing it back to “Unprocessed” from “Processed”