BPM using custom code to call BAQ and Process Job Adjustments only processes 1 record

,

I have a BMP that calls a baq that returns multiple results. The results are supposed to be used to process job adjustment entries. It is only processing the first record from the results of the baq.

Here is the code I am running. I am setting some variables prior to this call in the BPM so I can use them. I have tried the loop using both the != Null - which actually won’t process a record, and the .Rows.Count>0 which will always only process the first baq result. I have also confirmed that the baq will return more than one record.

What am I missing?

  Ice.Contracts.DynamicQuerySvcContract boDynamicQuery = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.DynamicQuerySvcContract>(Db);
  Ice.Tablesets.QueryExecutionTableset dsQueryExecution = new QueryExecutionTableset();
  
  
  ExecutionParameterRow drRow = new ExecutionParameterRow();
  drRow.ParameterID = "";  // name of parameter from BAQ
  drRow.ParameterValue = "";
  drRow.ValueType = "";
  drRow.IsEmpty = false;
  drRow.RowMod = "A";
  drRow.SysRowID = new Guid();

  dsQueryExecution.ExecutionParameter.Add(drRow);
  
  DataSet dsResults = boDynamicQuery.ExecuteByID("HoseCounterJobs", dsQueryExecution);
  
 
  // Lets Loop through our results
  if (dsResults.Tables[0] != null) //.Rows.Count > 0)
  {
    foreach (DataRow row in dsResults.Tables[0].Rows)
    {
    
    
     using(var JA=Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.JobAdjustmentSvcContract>(this.Db))

      {
      Erp.Tablesets.JobAdjustmentTableset jads = new Erp.Tablesets.JobAdjustmentTableset();
      var addLbrDtl = new Erp.Tablesets.JALaborDtlRow();

      addLbrDtl.ClockInDate = ClockInDate;
      addLbrDtl.LaborNote = "Hose Counter Assembly";
      addLbrDtl.AssemblySeq = AsmSeq;
      addLbrDtl.OprSeq = OpSeq;
      addLbrDtl.QtyCompleted = Convert.ToDecimal (dsResults.Tables[0].Rows[0] ["Calculated_cLaborQty"]);
      addLbrDtl.EmployeeNum = dsResults.Tables[0].Rows[0] ["Calculated_cEmployeeNum"].ToString();
      addLbrDtl.LaborQty = Convert.ToDecimal (dsResults.Tables[0].Rows[0] ["Calculated_cLaborQty"]);
      addLbrDtl.LaborType = dsResults.Tables[0].Rows[0] ["Calculated_cLaborType"].ToString();
      addLbrDtl.LaborHrs = 0;
      addLbrDtl.BurdenHrs = 0;
      addLbrDtl.Complete = true;
      addLbrDtl.OpComplete = true;
      addLbrDtl.company = Company;
      addLbrDtl.OpCode = dsResults.Tables[0].Rows[0] ["Calculated_cOpCode"].ToString();
      addLbrDtl.ResourceGrpID = dsResults.Tables[0].Rows[0] ["Calculated_cResourceGrpID"].ToString();
      addLbrDtl.JobNum = dsResults.Tables[0].Rows[0] ["Calculated_cJobNum"].ToString();
      addLbrDtl.LaborEntryMethod = "T"; 
      addLbrDtl.EnableLaborQty = true; 
      addLbrDtl.EnableScrapQty = true; 
      addLbrDtl.EnableDiscrepQty = true; 
      addLbrDtl.LaborDisTimeTypCd = true; 
      addLbrDtl.LaborDisPrjRoleCd = true; 
      addLbrDtl.RowMod = "U";
      jads.JALaborDtl.Add(addLbrDtl); 
      JA.CommitLaborAdj(ref jads); 
      JA.Dispose(); 

     }
      
    }
  }

Put your loop inside your using don’t create and dispose the object for every record.
Don’t use a dispose on your JA that’s what happens when you end a using automatically.
wrap the whole thing in a try catch and log to the event viewer in case something is falling through the cracks.

3 Likes

I have made the suggested changes. Still only executing on the first result in the query. This code is in an execute custom code widget on the jobentry.update method. I am using it for testing. The query I am calling is currently restricted to return the top 2 rows. I also changed it to return 3 rows to see if it would make a difference. It still only processes the first row of the returned set of values from the BAQ.

Pop an info message with the row count from your BAQ.

This is no longer any fun…
I have been trying to get any type of message box to pop up. No results so far.
I know that it executes this custom code block for one record from the BAQ as I can see the results.

So, why no message box using the following code?

    this.PublishInfoMessage( "Starting Here",Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
    
      Ice.Contracts.DynamicQuerySvcContract boDynamicQuery = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.DynamicQuerySvcContract>(Db);
      Ice.Tablesets.QueryExecutionTableset dsQueryExecution = new QueryExecutionTableset();
      
      
      ExecutionParameterRow drRow = new ExecutionParameterRow();
      drRow.ParameterID = "";  // name of parameter from BAQ
      drRow.ParameterValue = "";
      drRow.ValueType = "";
      drRow.IsEmpty = false;
      drRow.RowMod = "A";
      drRow.SysRowID = new Guid();

      dsQueryExecution.ExecutionParameter.Add(drRow);
      
      DataSet dsResults = boDynamicQuery.ExecuteByID("HoseCounterJobs", dsQueryExecution);
      
  // Check to see how many records are returned in the query
  
      //var ttlRecords = dsResults.Tables["Results"].Rows.Count;
      
      this.PublishInfoMessage( "Your Message",Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
      
      using(var JA=Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.JobAdjustmentSvcContract>(this.Db))
      
     
      
      // Lets Loop through our results
      if (dsResults.Tables[0].Rows.Count > 0)
      {
        this.PublishInfoMessage("Query Loop" + dsResults.Tables[0].Rows[0] ["Calculated_cJobNum"].ToString(),Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual,"","");
        
        Erp.Tablesets.JobAdjustmentTableset jads = new Erp.Tablesets.JobAdjustmentTableset();
       // var addLbrDtl = new Erp.Tablesets.JALaborDtlRow();
        foreach (DataRow dtrow in dsResults.Tables[0].Rows)
    
          {
          //Erp.Tablesets.JobAdjustmentTableset jads = new Erp.Tablesets.JobAdjustmentTableset();
          var addLbrDtl = new Erp.Tablesets.JALaborDtlRow();
 
          addLbrDtl.ClockInDate = ClockInDate;
          addLbrDtl.LaborNote = "Hose Counter Assembly";
          addLbrDtl.AssemblySeq = AsmSeq;
          addLbrDtl.OprSeq = OpSeq;
          addLbrDtl.QtyCompleted = Convert.ToDecimal (dsResults.Tables[0].Rows[0] ["Calculated_cLaborQty"]);
          addLbrDtl.EmployeeNum = dsResults.Tables[0].Rows[0] ["Calculated_cEmployeeNum"].ToString();
          addLbrDtl.LaborQty = Convert.ToDecimal (dsResults.Tables[0].Rows[0] ["Calculated_cLaborQty"]);
          addLbrDtl.LaborType = dsResults.Tables[0].Rows[0] ["Calculated_cLaborType"].ToString();
          addLbrDtl.LaborHrs = 0;
          addLbrDtl.BurdenHrs = 0;
          addLbrDtl.Complete = true;
          addLbrDtl.OpComplete = true;
          addLbrDtl.company = Company;
          addLbrDtl.OpCode = dsResults.Tables[0].Rows[0] ["Calculated_cOpCode"].ToString();
          addLbrDtl.ResourceGrpID = dsResults.Tables[0].Rows[0] ["Calculated_cResourceGrpID"].ToString();
          addLbrDtl.JobNum = dsResults.Tables[0].Rows[0] ["Calculated_cJobNum"].ToString();
          addLbrDtl.LaborEntryMethod = "T"; 
          addLbrDtl.EnableLaborQty = true; 
          addLbrDtl.EnableScrapQty = true; 
          addLbrDtl.EnableDiscrepQty = true; 
          addLbrDtl.LaborDisTimeTypCd = true; 
          addLbrDtl.LaborDisPrjRoleCd = true; 
          addLbrDtl.RowMod = "U";
          jads.JALaborDtl.Add(addLbrDtl); 
          JA.CommitLaborAdj(ref jads); 
    
         }
          
      }

Reminder please review Code Syntax Highlighting in Posts this helps with readability

Do any of the info messages pop? Where is this BPM on a data directive?

None of the message boxes in this code bock pop up. This is code is executed on the Job Update method directive. The BPM is triggered when the value of the Analysis Code is equal to a specific value. It sets 4 variables that are used in the customer code block which is called right after the last variable is initialed. I have an exception message after the Execute custom code widget. I am using the Job Update so I can test that this is actually working and I am using the Exception message to stop the actual job update since I don’t really want the job updated.

Send a screenshot of the entire bpm workflow

Here is the BPM workflow

With that exception message in there i’m not sure how epicor will prioritize message display.

Is the BAQ complicated or could you just write a straight linq query in your BPM and call it a day?

The baq is not that complicated. I think there is something wrong with the tool. I have created another similar bpm and the message boxes appear just fine from the custom code widget. I am going to delete the existing widget and rebuild it from scratch. Thanks for your help. I will post my findings once I rebuild it.

Okay, I found out part if not all of the issue. The last widget is a raise exception. If that widget is in place, none of the other messages will appear. I will do some more testing, but it appears that the Raise Exception widget is causing the Execute Custom code widget to not process correctly. Rather odd…

Okay, finally figured this out. 2 issues. First, if there is a widget to raise exception, for some reason the messages in the custom code will not display.
Regarding why it wasn’t looping through the total records returned from the BAQ…in my code, I had foreach (DataRow dtrow…however in the fields that were supposed to pass the values to the job adjustment method, I was using dsResults…so it was only executing the first loaded value.