You try to put a workcenter into Downtime, MES will then attempt to stop all the running labor.

Downtime won’t start because an operation was closed in ERP and someone started Labor on the Operation.  The system tries to stop this old labor, and it can't change the status of the operation from closed to started. 




SQL script to "remove" or close all of those situations


For MES Version 4.8 and 4.9 “DurationinMinutes” will need to be change to “DurationinHours”


LaborStatusTypeId = 2, -- Change status to Stopped
DurationInMinutes = 0, -- Assign 0 minutes of labor
StopDate = Startdate, -- Change StopDate to StartDate
ChangedDate = GETUTCDATE(),
ChangedById = 0
FROM Labor as L INNER JOIN ManufactureOrderOperation AS M ON L.ManufactureOrderOperationId = M.Id
INNER JOIN ManufactureOrder as MO on M.ManufactureOrderId = MO.Id
WHERE (LaborStatusTypeId = 1) AND (StopDate IS NULL) -- Where labor is running
AND (MO.OrderStatusId >= 5 OR MO.SoftDeleted = 1 -- and (Order is Completed, Cancelled or removed
             OR M.OrderStatusId >=5 OR M.SoftDeleted = 1) -- or Operation is Completed, Cancelled or removed)