GetState (of State Machine) Function

The GetState() function retrieves the current state of the specified State Machine. The name of the State Machine may be any valid State Machine and not only the one defined for this action (as long as this is qualified). If the named state machine defined for the function does not exist, the Platform throws an EvaluationException and logs an error to the drm.log file.

You can use this function to determine the current state of a state machine and take action based on the returned value. For example, if the trigger type is a StateChange, you might check the state and run an action based on the current state. If the trigger type is an Alarm, you might check the current state and transition the state machine to a different state.

Using this function, you can reference states for state machines other than the one associated with the trigger message.

Usage Notes:

The Platform automatically creates a data item whose name is the name of the state machine. The data item is a String that contains the current state. You do not need to create a data item to store the current state.

Format:

String GetState(String statemachine)

where:

statemachine is the name of the State Machine for which you are getting its state.

Note: If you use this function and the State Machine is in its initial state (the first one in the list of states), this function returns that initial state.

Example:

The following example determines if the current state for the Transit State Machine is "Final Destination" and, if true, runs the CreateAlarm() action.

If GetState("Transit") == "Final Destination"

Then: CreateAlarm("Destination reached", 100)