Skip to main content

system.mes.shift.getCurrentShift

Description

Gets the current Shifts at the given location. Optionally, you can specify a timestamp (milliseconds since epoch) to get the shift active at that moment.

Syntax

system.mes.shift.getCurrentShift(locationIdOrPath)
system.mes.shift.getCurrentShift(locationIdOrPath, timestampMillis)

Parameters

Method 1: By Location at Current Time

ParameterTypeNullableDescription
locationIdOrPathStringFalseThe location ID or path to find the current shift for.

Method 2: By Location at Specific Timestamp

ParameterTypeNullableDescription
locationIdOrPathStringFalseThe location ID or path to find the current shift for.
timestampMillisLongTrueThe timestamp (ms since epoch) to evaluate. If null, uses the current time.

Returns

Returns a JSON representation of the shift. Returns nothing if no shift is found.

NameTypeDescription
nameStringThe shift name.
descriptionStringDescription of the shift.
shiftScheduleNameStringThe name of the schedule defining this shift's timings.
shiftScheduleSourceStringThe source of the schedule (e.g., IGNITION_SCHEDULE, IGNITION_EXPRESSION).
locationIdString (ULID)The location where the shift runs.
locationPathStringThe path of the location (for display purposes).
currentRecordIdString (ULID)The current shift record id, if any.
runningConflictStrategyStringStrategy for conflicts (e.g., STOP_PREVIOUS, THROW_EXCEPTION).
startTriggerExpressionStringExpression used to determine when the shift should start.
startTriggerTypeStringTrigger type used to start the shift (e.g., RISING_EDGE, FALLING_EDGE, CHANGE).
stopTriggerExpressionStringExpression used to determine when the shift should end.
stopTriggerTypeStringTrigger type used to end the shift (e.g., RISING_EDGE, FALLING_EDGE, CHANGE).
idString (ULID)The ULID of the shift.
notesStringNotes related to the shift.
enabledBooleanIndicates if the shift is active and enabled.
spare1StringAdditional field for user-defined context.
spare2StringAdditional field for user-defined context.
spare3StringAdditional field for user-defined context.

Code Examples

# Current shift for a location
shift = system.mes.shift.getCurrentShift('DairyCo/Plant1/Line1')
print(shift)

# Current shift at a given timestamp
shiftAtTime = system.mes.shift.getCurrentShift('DairyCo/Plant1/Line1', 1735689600000)
print(shiftAtTime)