Labor Function creates several LaborQty

I’ve added a button to the top of the Assembly Details page within the Job Entry that is supposed to add 1 labor quantity to the operation. The issue i’m having is it loops around 3-6 times adding Labor Quantity each time. I can’t find anything in my code to signify this, any advice?

var JobHead = this.Db.JobHead.Where(x => x.JobNum == jobNumber && x.Company == Session.CompanyID).FirstOrDefault();
var emp = this.Session.EmployeeID;

if (JobHead != null)
{

  var AsmHead = this.Db.JobAsmbl.Where(x => x.AssemblySeq == AsmSeq && x.Company == Session.CompanyID).FirstOrDefault();
  
  if (AsmHead != null)
  {
  
    var AllOps = this.Db.JobOper.Where(x => x.AssemblySeq == AsmHead.AssemblySeq && x.Company == Session.CompanyID).AsEnumerable();
    
    if (AllOps != null)
    {
    
      //this.PublishInfoMessage($"{AllOps.Count()} & {emp}", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "title 1", "title 2");
    
      foreach (var op in AllOps)
      {
      
        try
        {
        
          //this.PublishInfoMessage($"ASM: {op.AssemblySeq} -- Op Seq: {op.OprSeq} -- Code: {op.OpCode} -- Description: {op.OpDesc}", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "LaborQuant", "LaborQuantityUpdate");
        
          var context = Ice.Services.ContextFactory.CreateContext<ErpContext>();
          
          using (var lbr = ServiceRenderer.GetService<Erp.Contracts.LaborSvcContract>(context))
          {
          
            string msg;
            var ts = new Erp.Tablesets.LaborTableset();
            ts.LaborDtl[0].RowMod = "U";
            
            lbr.GetNewLaborDtlNoHdr(ref ts, "300080", false, DateTime.Today, 0, DateTime.Today, 0);
            lbr.DefaultJobNum(ref ts, jobNumber);
            lbr.LaborRateCalc(ref ts);
            lbr.DefaultAssemblySeq(ref ts, AsmSeq);
            lbr.LaborRateCalc(ref ts);
            lbr.ChangeLaborDtlOprSeq(ref ts, op.OprSeq, out msg);
            lbr.LaborRateCalc(ref ts);
            lbr.DefaultLaborQty(ref ts, 1, out msg);
            lbr.CheckWarnings(ref ts, out msg);
            lbr.Update(ref ts);
            lbr.ValidateChargeRateForTimeType(ref ts, out msg);
            lbr.SubmitForApprovalBySelected(ref ts, false, out msg);
          
          }
          
          AsmHead.AsmCompDate_c = DateTime.Today;
          AsmHead.AsmComplete_c = true;
          
          this.Db.SaveChanges();
        
        }
        catch
        {
        
          // perform actions if there is an error
        
        }
      }
    }
  }
}

I’ve created a few UD fields to hold data within the JobAsmbl table. I’ve also been having issues with the Session.EmployeeID as it only works on the first loop and returns null for the employee after the fact.

I also have read about the LaborTableset.LaborDtl[0].RowMod = "U" but i am unsure of the reasoning for this.

Neither your AsmHead or AllOps is being filtered down to the job you selected. You are getting the first result of AsmHead and AllOps for that head, but that head isn’t being filtered to that job so it probably is grabbing the wrong head from a different job with more ops.

We don’t use assemblies here so everything is 0 for us so take this advice with a grain of salt.

I appreciate you responding @LoganS!

That makes sense and I don’t see why I didn’t catch that previously. I have message boxes throughout as I like to be able to see the data that i’m passing. Ihave a box set to popup for each operation loop displaying the data and it freezes on the last op in the assembly. Why would that be? I am unable to close the box and have to close the Job Entry module and reopen to continue working again.

@dakhit You may want to use WriteEntry rather than message boxes for tracing since they can sometimes get queued. The write entries show in the App server Evet Viewer.

Ice.Diagnostics.Log.WriteEntry(Msg);

Thanks @gpayne! Which log does this output to? I was checking within my appData\Roaming\epicor folder but wasn’t able to find the specific packets inside.

@dakhit Soo this is an On Prem thing since the event viewer is on the app server. I looked and saw that you were MT SaaS so I don’t know if you have access to the server logs. Sorry

No @gpayne, we utilize the SaaS. Within the user settings, you can setup the trace for log files and select (from a limited list) where to store the logs. In my third environment, I have this permanently setup for my user and it just saves whatever I do in the log files.

We are fairly new with the system as we went live Sept 6 this year. I’m still figuring out where everything is and what it all means plus tips and tricks through trial and error. I may have a poor way of explaining what I’m looking for.

@dakhit For me it in in the server folder called ServerLog.txt is the default name. The messages are tagged IceAppServer msg and look like this.

Since this is inside of a customization you could do the standard c# function MessageBox.Show(string) to troubleshoot. Print out helpful information, such as variables, markers to see where you get to in code, etc and figure out where it’s breaking. If it freezes at the end of a loop it sort of sounds like an infinite loop but it could also be trying to utilize null information and locking up the screen too, or something totally different.