🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators stateMachineForceMode
This page was created by Hans.karlsen on 2018-04-01. Last edited by Wikiadmin on 2026-07-29.

You can use stateMachineForceMode in an OCL action when you must correct an object's state attribute even though the configured state-machine transitions do not permit the change; it is intended for developers and debugging or corrective work.

What stateMachineForceMode does

A state machine controls the allowed changes to a state attribute. Its transitions and guards enforce the business rules configured for that object.

stateMachineForceMode gives you permission for one direct write to a specified state attribute. Use it immediately before assigning the required state value.

self.stateMachineForceMode('State');
self.State := 'State3'

In this example:

  • State in stateMachineForceMode('State') is the name of the state attribute.
  • 'State3' is the state value assigned to that attribute.

The operator bypasses the state machine for that single assignment. It does not add a transition or change the state-machine definition.

When to use it

Use force mode only when the object's current state is incorrect and there is no legal transition to the state you need. For example, a production object may have been set to Discarded accidentally, while the deployed state machine has no transition that can return it to an active state.

Prefer a normal state-machine transition whenever one exists. Force mode bypasses the guards and transition rules that normally protect the object's lifecycle.

Do not work around the state machine by updating the database outside the framework. Such changes are not recorded in the MDrivenServerSynk table and therefore do not propagate to configured MDrivenServer slaves or receive the timestamp handling provided by a HistorySlave configuration.

Force one state change

  1. Identify the state attribute that the state machine controls. For example, the attribute may be named State.
  2. Call stateMachineForceMode on the object and pass that attribute's name as a string.
  3. Assign the required state value as the next write to that attribute.
self.stateMachineForceMode('State');
self.State := 'State3'

One write means one write

Force mode is consumed by the next write to the specified state attribute. It does not remain active for later assignments.

The following action fails on the second assignment to State, because only the first write has force-mode permission:

self.stateMachineForceMode('State');
self.State := 'State3';
self.State := 'State3'

If you must force two assignments, request force mode before each one:

self.stateMachineForceMode('State');
self.State := 'State3';
self.stateMachineForceMode('State');
self.State := 'State3'

Common mistakes

Mistake Correct approach
Passing a state value to stateMachineForceMode, such as stateMachineForceMode('State3'). Pass the controlled attribute name: stateMachineForceMode('State').
Calling force mode once and expecting multiple state writes to be allowed. Call stateMachineForceMode again immediately before each forced write.
Using force mode for ordinary workflow changes. Use the configured transitions for ordinary workflow changes; reserve force mode for correction when no legal path exists.
Updating the state column directly in the database. Make the correction through the framework so MDrivenServer synchronization and history handling can record it.

See also