How to determine with a query if someone is logged into MES?

In the database or BAQ, how would you determine if a user is currently logged into MES?

What tables do I need to check against?

1 Like

I look at Labor Head where there is no logout time.

2 Likes

LAborhed.ActiveTrans = 1

1 Like

Depending on the exact desired outcome and context here, you may otherwise be looking for their license type if it’s a DC license or not. That is a static GUID that I’m sure there is a reference for on the site here.

2 Likes

Why not just use the out of the box Shop Tracker?

2 Likes

The varietally of questions/suggestions here highlights the need for more context and specificity in the original questions lol!

2 Likes

Thank you for the responses. I’m going to check against the LaborHed table.

My use case is on a webpage external to Epicor. I need to check if the user is logged in or not and if they aren’t I will log them in via REST calls.

1 Like

Scott, I guess do you mean clocked in or logged in, like consuming a license?

That’s exactly how my RFID timeclock works. Conversely clocks them out when ActiveTrans = 1, but that could be stripped out if you are only looking for one way.

This is my REST call. This is back before we built EFX support into the epicor rest nuget!

private void ClockInOut()
        {
            var client = new RestClient($"https://{Properties.Settings.Default.ServerHost}/{Properties.Settings.Default.AppServer}/api/v2/efx/{Properties.Settings.Default.Company}/EmpProcesses/RFIDCardClockInOut");
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("X-API-Key", Properties.Settings.Default.APIKey);
            string encoded = System.Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(Properties.Settings.Default.AppUsername + ":" + Properties.Settings.Default.AppPassword));
            request.AddHeader("Authorization", $"Basic {encoded}");
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", "{\r\n  \"RFIDAccessID\": \"" + _lastScannedID + "\"\r\n}", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            dynamic content = Newtonsoft.Json.JsonConvert.DeserializeObject(response.Content);

            // If there are errors display them and bow out
            _infoTimer.Start();
            if (!string.IsNullOrEmpty(content.Errors.Value))
            {
                txtMessages.Text = content.Errors.Value;
                txtMessages.BackColor = Color.FromArgb(255, 199, 206);
                txtMessages.ForeColor = Color.FromArgb(156, 0, 6);
                picStatus.Image = RFIDEmployeePunchClock.Properties.Resources.redx;
            }
            else
            {                
                txtScanCardInstruct.Visible = false;
                txtEmpInfo.Text = $"{content.EmpName.Value} (#{content.EmpID.Value})";
                txtDirection.Text = ((bool)content.ClockedIn.Value) ? $"Clocked Into {content.Shift.Value}" : "Clocked Out";
                txtMessages.Text = "Valid Punch";
                txtMessages.BackColor = Color.FromArgb(198, 239, 206);
                txtMessages.ForeColor = Color.FromArgb(0, 97, 0);
                picStatus.Image = RFIDEmployeePunchClock.Properties.Resources.greencheck;
            }
        }

The EFX method called from our C# app.

this.CallService<EmpBasicSvcContract>(ef => {
  try
  {   
    // Ensure access code passed
    if(string.IsNullOrEmpty(RFIDAccessID))
    {
      throw new Exception("Access ID is required.");
    }
    
    // Get the employee from the rfid code
    var employee = Db.EmpBasic.Where(x => x.Company == callContextClient.CurrentCompany && x.AccessCardID_c == RFIDAccessID).FirstOrDefault();
    if (employee == null)
    {
      throw new Exception("Invalid access ID card scanned. Please see your supervisor.");
    }
    else
    {
      EmpID = employee.EmpID;
      EmpName = employee.Name;
    }    
      
    // Get shift info
    var shift = Db.JCShift.Where(x => x.Company == callContextClient.CurrentCompany && x.Shift == employee.Shift).FirstOrDefault();
    if (shift == null)
    {
      throw new Exception("No default shift assigned to the employee. Unable to clock in. Please see your supervisor.");
    }
    else
    {
      Shift = shift.Description.ToString();
    }    
    
    // Determine if we should clock in or out
    var laborHed = Db.LaborHed.Where(x => x.Company == callContextClient.CurrentCompany && x.EmployeeNum == employee.EmpID && x.ActiveTrans).FirstOrDefault();
    if(laborHed == null)
    {
      
      #if DEBUG
      this.EfxLib.LoggingUtils.LogTraceBpm($"ClockIn: {EmpID} {Shift}", this.ToString(), "Information", 100);  
      #endif
      ef.ClockIn(EmpID, shift.Shift);
      ClockedIn = true;
    }
    else
    {
      // Ensure there are no active labor detail records
      var laborDtl = Db.LaborDtl.Where(x => x.Company == callContextClient.CurrentCompany && x.LaborHedSeq == laborHed.LaborHedSeq && x.ActiveTrans).FirstOrDefault();
      if (laborDtl == null)
      {
        string tempEmpID = EmpID;
        ef.ClockOut(ref tempEmpID);
        ClockedIn = false;
        
      #if DEBUG
      this.EfxLib.LoggingUtils.LogTraceBpm($"ClockOut: {EmpID} {Shift}", this.ToString(), "Information", 200);  
      #endif
      }
      else
      {
        throw new Exception("You are still active on an activity. Please clock out of the active activity before clocking out for the day.");
      }      
    }
  }
  catch (Exception ex)
  {
    Errors = ex.Message.ToString();
  }
});
2 Likes