The SetState() action changes the state of a State Machine so that the next time the State Machine runs (for any Trigger type), the specified state is the current state. The name of the State Machine can be any valid State Machine.
Important!
You do not need to set the initial state of a state machine. For example,
you do not need to create an expression rule with a Registration message
as its trigger and its action (Then expression) to set the state of a
state machine to the first state. The Platform defaults to the first state.
In addition, if you create a state machine with three states (for example,
A, B, and C) and subsequently delete the third state while the asset is
in that third state, the asset remains in that third state. It does NOT
revert to its initial state. To return the asset to its initial state,
create a data item and for its name, specify the name of the state machine.
This data item can then be set to the name of the initial state to restore
the asset to the initial state. You can set the data item using an expression rule or a SetDataItem action
that sets the data item (which can be run from the Asset dashboard).
SetState(String statemachine, String statename)
where:
statemachine - name of the State Machine for which you are setting its state.
statename - name of the state you want to set as the current state for this state machine; the state you define here must already exist.
The following example sets the state of State Machine Transit to Running:
Then/Else: SetState("Transit", "Running")