We use the MES Idle Time feature that sums up time not associated with an activity, and creates an indirect LaborDtl record upon clock-out. We also use require Supervisor approval for all labor records.
When clocking out manually via MES, that Idle Time record is ‘Submitted’ and requires Supervisor approval. This is expected and desired behavior.
I have a task that runs nightly to automatically clock out employees that have not clocked out for the day. I use the BAQ Export Process as the scheduled task, and a Data Directive on Ice.SysTaskParam where ParamCharacter = BAQ Name. I have custom code in the Data Directive that calls the EmpBasicService.ClockOut() method for each clocked-in employee.
When the directive code runs, the MES Idle Time record is automatically ‘Approved’ (by our system agent user). If you open the record in Time & Expense Entry, recall, and re-submit the record, it again goes straight to ‘Approved’ without entering the ‘Submitted’ state. The LaborDtl record seems to be corrupted in some way.
When I call the EmpBasicSvc.ClockOut method via REST (as the system agent user) the record is NOT automatically approved. Again, this is what we want.
Why would this behavior be different only when calling the method via the Data Directive Custom Code?
Code:
var employees = Db.EmpBasic.Where(emp => emp.Company == Session.CompanyID && empIDs.Contains(emp.EmpID)).ToList();
var empBasicService = ServiceRenderer.GetService<Erp.Contracts.EmpBasicSvcContract>(Db);
foreach(string empID in empIDs)
{
var employee = employees.FirstOrDefault(emp => emp.EmpID == empID);
var clockOutResult = new object[] { empID,
employee?.Name ?? "",
employee?.SupervisorID ?? "",
DateTime.Now,
false,
"" };
try
{
var e = empID;
empBasicService.ClockOut(ref e);
}
catch(Exception ex)
{
clockOutResult[4] = true;
clockOutResult[5] = ex.Message;
}
finally
{
clockOutResults.Add(clockOutResult);
}
}
As a test, before the directive kicks in, manually clock one of them out while gathering a client trace. If this leaves the record in the desired state, inspect the trace to see if any other calls are made.
Do they have any active labor details at this point? I built something similar and included some code to check if they had active labor details and ended them prior to calling ClockOut. I wouldn’t expect this result but may be worth investigating.
Hi Adam,
I have inspected the trace and there are no additional calls that need to be made. Also, I’ve called the ClockOut method via REST (which should perform the action same as calling it from the custom code), and it works correctly.
I have code that runs before this point to end any active labor details. I have test the code with and without that piece, to ensure that wasn’t causing a problem. Unfortunately I get the same result either way.
Here are some examples of LaborDtl (select fields). There are obvious differences between the one created via the Custom Code and the other methods. Several missing pieces of information.
Can you please help me in doing the auto clock out setup through BAQ & Data directives? since some of our employees are forgetting to clock out and it ends up in huge time fixing for the payroll. The autoclock out is the best solution.
It would be great if you can provide me the steps.