ProjectSvcContract CreateWBSPhaseJob - Invalid Operation Error

I am trying to complete an UBAQ that creates Project WBS Phases and related WBS Phase jobs.

I trying to use the CreateWBSPhaseJob method in the base UBAQ Update() Method Directive to create the job but keep getting an InvalidOperationException Error: Cannot add row to another table.

foreach(var r in ttResults.Where(o=>o.RowMod=="U" && o.OpMaster_OPType == "SRV")){
      
        using(var projSvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.ProjectSvcContract>(this.Db)) {
        
          vProjectTableset = projSvc.GetByID(r.Project_ProjectID);
        
          if(vProjectTableset.ProjPhase.Where(o=>o.ProjectID == r.Project_ProjectID && o.PhaseID == r.JCDept_JCDept + "-" +r.OpMaster_OpCode).Count() == 0) {
          
             //Create Sales Order Line
        
              using(var soSvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.SalesOrderSvcContract>(this.Db)) {

                  vSalesOrderTableset = soSvc.GetByID(Int32.Parse(r.Project_ProjectID));
            
                  if(vSalesOrderTableset != null) { 
            
                      soSvc.GetNewOrderDtl(ref vSalesOrderTableset, Int32.Parse(r.Project_ProjectID));
                      
                      var newOrderDtl = vSalesOrderTableset.OrderDtl.LastOrDefault();
                      newOrderDtl.PartNum = r.JCDept_JCDept + "-" +r.OpMaster_OpCode;
                      newOrderDtl.LineDesc = r.OpMaster_OpDesc;
                      newOrderDtl.ProjectID = r.Project_ProjectID;
                      newOrderDtl.RowMod = "A";
                      
                      soSvc.Update(ref vSalesOrderTableset);
                 }
          
              soSvc.Dispose();
              
              }
        
          projSvc.GetNewProjPhase(ref vProjectTableset, r.Project_ProjectID);
        
         }
          
     
          vProjectTableset.ProjPhase.Last().PhaseID = r.JCDept_JCDept + "-" +r.OpMaster_OpCode;
          vProjectTableset.ProjPhase.Last().Description =  r.OpMaster_OpDesc;
          vProjectTableset.ProjPhase.Last().InvMethod = "FF";
          vProjectTableset.ProjPhase.Last().RevMethod = "INV";
          vProjectTableset.ProjPhase.Last().OrderNum = vSalesOrderTableset.OrderDtl.LastOrDefault().OrderNum;
          vProjectTableset.ProjPhase.Last().OrderLine = vSalesOrderTableset.OrderDtl.LastOrDefault().OrderLine;
          vProjectTableset.ProjPhase.Last().SalesCatID = r.JCDept_JCDept;       
       
          projSvc.Update(ref vProjectTableset);

 *projSvc.CreateWBSPhaseJob(r.Project_ProjectID, vProjectTableset.ProjPhase.LastOrDefault().PhaseID , ref vProjectTableset);*

projSvc.GetNewPBWrkMeasuredHead(ref vProjectTableset, r.Project_ProjectID);
            
          var newPBWMHead = vProjectTableset.PBWrkMeasuredHead.LastOrDefault();
      
          if(newPBWMHead != null) {
          
              newPBWMHead.ActivityUnit = "L";    
              newPBWMHead.Description = r.OpMaster_OpDesc;
              newPBWMHead.Details = r.OpMaster_CommentText;
              newPBWMHead.DocPricePerUnit = r.OpMaster_BillLaborRate;
              newPBWMHead.PricePerUnit = r.OpMaster_BillLaborRate;
              newPBWMHead.DocTotalAmt =r.OpMaster_BillLaborRate;
              newPBWMHead.TotalAmt = r.OpMaster_BillLaborRate;
              newPBWMHead.MeasuredWorkID = r.Project_ProjectID + ":" + r.OpMaster_OpCode;
              newPBWMHead.QtySurveyor = r.Project_ConProjMgr;
              newPBWMHead.TotalQty = 1;
         
              projSvc.Update(ref vProjectTableset);
              
              vProjectTableset.ProjPhase.LastOrDefault().MeasuredWorkID = newPBWMHead.MeasuredWorkID;
              vProjectTableset.ProjPhase.LastOrDefault().RowMod = "U";
              
              projSvc.Update(ref vProjectTableset);
         
            } 
            
            projSvc.Dispose();
          }
}

Error:

Server Side Exception

BPM runtime caught an unexpected exception of ‘InvalidOperationException’ type.
See more info in the Inner Exception section of Exception Details.

Exception caught in: Epicor.ServiceModel

Error Detail

Description: BPM runtime caught an unexpected exception of ‘InvalidOperationException’ type.
See more info in the Inner Exception section of Exception Details.
Program: Epicor.ServiceModel.dll
Method: set_Table
Line Number: 202
Column Number: 21
Original Exception Type: InvalidOperationException

Client Stack Trace

at Epicor.ServiceModel.Channels.ImplBase1.ShouldRethrowNonRetryableException(Exception ex, DataSet[] dataSets) at Ice.Proxy.BO.DynamicQueryImpl.Update(DynamicQueryDataSet queryDS, DataSet queryResultDataset) at Ice.Adapters.DynamicQueryAdapter.<>c__DisplayClass27_0.<Update>b__0(DataSet datasetToSend) at Ice.Adapters.DynamicQueryAdapter.ProcessUbaqMethod(String methodName, DataSet updatedDS, Func2 methodExecutor, Boolean refreshQueryResultsDataset)
at Ice.Adapters.DynamicQueryAdapter.Update(DynamicQueryDataSet queryDS, DataSet updatedDS, Boolean refreshQueryResultsDataset)
at Ice.UI.App.BAQDesignerEntry.BAQTransaction.b__380_0(Int32& rowReturned)
at Ice.UI.App.BAQDesignerEntry.Forms.BAQDiagramForm.ShowQueryResults(DataSet dsResults, getQueryResult getResults, ReportAdditionalInfo additionalInfo)
at Ice.UI.App.BAQDesignerEntry.BAQTransaction.CallUpdate()

Inner Exception

The row cannot be added to another table.

It seems to be my call to the Project Service CreateWBSPhaseJob method that throws this error:

projSvc.CreateWBSPhaseJob(r.Project_ProjectID, vProjectTableset.ProjPhase.LastOrDefault().PhaseID , ref vProjectTableset);

I am using the service to do a lot of other work with no issue, but this particular method I cannot get to work.

Any help would be greatly appreciated. I got the approach to work on a Post Update Project BPM, but errors when implemented along with the above UBAQ update.

1 Like

Have you got any solution on that? I’m trying to create the project job and the wbs phase jobs via a function and I get this error everytime