Skip to main content

system.mes.shift.saveShift

Description

Creates or updates a Shifts record in the system based on the provided parameters.

Syntax

system.mes.shift.saveShift(**shift_data)

Parameters

ParameterTypeNullableDescription
locationIdString (ULID)FalseThe ULID of the location where the shift runs.
locationPathStringTrueThe path of the location where the shift runs. For display purposes.
nameStringFalseThe name of the shift.
descriptionStringTrueA detailed description of the shift.
shiftScheduleNameStringTrueThe name of the schedule that defines this shift's timings (when using schedule-based timing).
shiftScheduleSourceString (Enum)FalseThe source of timing (e.g., IGNITION_SCHEDULE, IGNITION_EXPRESSION).
currentRecordIdString (ULID)TrueThe current shift record id for the shift (if any).
runningConflictStrategyString (Enum)FalseStrategy when a new shift starts while another is running (e.g., STOP_PREVIOUS, THROW_EXCEPTION).
startTriggerExpressionStringTrueThe expression used to determine when the shift should start.
startTriggerTypeString (Enum)FalseThe trigger mechanism used to start the shift (e.g., RISING_EDGE, FALLING_EDGE, CHANGE).
stopTriggerExpressionStringTrueThe expression used to determine when the shift should end.
stopTriggerTypeString (Enum)FalseThe trigger mechanism used to end the shift (e.g., RISING_EDGE, FALLING_EDGE, CHANGE).
idString (ULID)TrueThe ULID of the shift (optional, used for updating an existing shift).
notesStringTrueNotes related to the shift.
enabledBooleanTrueIndicates if the shift is active and enabled. Default value is true.
spare1StringTrueAdditional field for user-defined context.
spare2StringTrueAdditional field for user-defined context.
spare3StringTrueAdditional field for user-defined context.

Returns

Returns a JSON representation of the saved shift.

Code Examples

# Create a new shift and save it
shift = system.mes.shift.newShift()
shift['locationId'] = '01JAP8RJBN-8ZTPXSGY-J9GSDPE1'
shift['name'] = 'Morning Shift'
shift['shiftScheduleName'] = 'Weekday Schedule'
shift['shiftScheduleSource'] = 'IGNITION_SCHEDULE'
shift['startTriggerType'] = 'RISING_EDGE'
shift['stopTriggerType'] = 'FALLING_EDGE'

saved = system.mes.shift.saveShift(**shift)
print(saved)

# Update an existing shift
shift2 = system.mes.shift.newShift()
shift2['id'] = saved.id
shift2['locationId'] = '01JAP8RJBN-8ZTPXSGY-J9GSDPE1'
shift2['name'] = 'Morning Shift'
shift2['shiftScheduleName'] = 'Weekday Schedule'
shift2['shiftScheduleSource'] = 'IGNITION_SCHEDULE'
shift2['startTriggerType'] = 'RISING_EDGE'
shift2['stopTriggerType'] = 'FALLING_EDGE'
shift2['description'] = 'Updated description'

updated = system.mes.shift.saveShift(**shift2)
print(updated)