State Machine Workflows

When you save a form sequence, Forms Builder automatically creates a new state machine workflow definition. The new workflow definition contains a state for each form included in the sequence. The order in which the states appear in the workflow definition match the order in which the forms were dropped onto the Layout pane when creating the sequence in Sequence Designer.

You can access the workflow using Workflow Composer For more information, see Open the Workflow for a Sequence. You can then edit, save, and publish the workflow using Workflow Composer.

State machine workflows provide a modeling style with which you can model your workflow in an event-driven manner. A StateMachine activity contains the states and transitions that make up the logic of the state machine and can be used anywhere an activity can be used. To create a state machine workflow, States are added to a StateMachine activity, and Transitions are used to control the flow between states.

State

A state machine workflow must have one and only one initial state and at least one final state. Each state that is not a final state must have at least one transition.

The following image shows a state machine workflow with five states and multiple transitions. The initial state named Welcome represents the first state in the workflow. This is designated by the line leading to it from the Start node. The final state named End represents the point at which the workflow is completed.

State Machine

  • To add a state to a workflow, drag the State activity from the State Machine section of the Toolbox and drop it onto a state machine workflow in the Designer pane.

    Toolbox - State Machine activities

  • To configure a state as the Initial State, right-click the State in the Designer pane and select Set as Initial State. If there is no current initial state, the initial state can be designated by dragging a line from the Start node to the state.

  • To add a final state to a workflow, drag a FinalState activity from the State Machine section of the Toolbox and drop it onto a state machine workflow in the Designer pane. A final state is a state that has its IsFinal property set to true, has no Exit activity, and no transitions originating from it.

A state can have an Entry and an Exit action. (A state configured as a final state only has an entry action). When a workflow instance enters a state, any activities in the Entry action execute. When the Entry action is complete, the triggers for the state’s Transitions are checked. When a transition to another state is confirmed, the activities in the Exit action are executed. After the Exit action completes, the activities in the transition’s action execute, and then the new state is transitioned to, and its Entry actions are executed.

Double-click the icon of a State activity to view its details.

View State details

The following image shows the details of a State activity.

State activity

  • When debugging a state machine workflow, breakpoints can be placed on the root state machine activity and states within the state machine workflow. Breakpoints may not be placed directly on the transitions, but they may be placed on any activities contained within the states and transitions.

  • When editing a workflow definition, keep in mind that a state in the state machine workflow equates to a form within the sequence. The name of a State must match the name of a Form to be rendered properly. If Renderer encounters a State in workflow definition that does not match name of any Form created in Form Designer, an error similar to the following will be generated.

    Missing Form error message

Transition

All states must have at least one transition, except for a final state which may not have any transitions. Transitions may be added after a state is added to a state machine workflow, or they can be created as the State activity is dropped into the Designer pane.

To add a state and create a transition in one step, drag a State activity from the State Machine section of the Toolbox and hover it over another State in the Designer pane. When the dragged State is over another State, four triangles will appear around the other State. If the State is dropped onto one of the four triangles, it is added to the state machine and a transition is created from the source State to the destination State.

To create a transition after a state is added, drag a line from one state to another state. The yellow box indicates the start point of the line.

Create transition

To edit the transition details, double-click the transition line.

A transition may have a Trigger, a Condition, and an Action.

A transition’s Trigger is checked when the transition’s source state’s Entry action is complete. Typically, the Trigger is an activity that waits for some type of event to occur, but it can be any activity, or no activity at all. Once the Trigger activity is complete, the Condition if present, is evaluated.

  • If there is no Trigger activity, then the Condition is immediately evaluated.

  • If the Condition evaluates to false, the transition is cancelled, and the Trigger activity for all transitions from the state are rescheduled.

  • If there are other transitions that share the same source state as the current transition, those Trigger actions are cancelled and rescheduled as well.

  • If the Condition evaluates to true, or there is no condition, then the Exit action of the source state is executed, and then the Action of the transition is executed. When the Action completes, control passes to the Target state.

The following image shows the transition designer for a transition with a Next trigger that was automatically inserted by Forms Builder when the state machine workflow was created. Forms Builder will also insert Back triggers to enable users to navigate forward and back through a sequence.

Transition details

Note that the Next and Back triggers created by Forms Builder are WaitForFormBookmark activities. To add this trigger to a workflow, drag a WaitForFormBookmark activity from the Toolbox to the Designer pane. When you modify an existing workflow to add new transitions, be sure to add a WaitForFormBookmark activity as a trigger.

Next trigger - WaitForFormBookmark

Shared Trigger Transition

Transitions that share a common trigger are known as shared trigger transitions. Each transition in a group of shared trigger transitions has the same trigger, but a unique Condition and Action. An example for shared trigger transitions is a form with multiple value selection options which routes to different sub forms depending on a value selection (see Multi Route Forms).

To create a share trigger transaction, drag a line from the connection point (yellow circle) of the trigger.

Shared trigger transaction   

To add additional actions to a transition and create a shared transition, click the yellow circle that indicates the start of the desired transition and drag it to the desired state. The new transition will share a same trigger as the initial transition, but it will have a unique condition and action. Shared transitions can also be created from within the transition designer by clicking Add shared trigger transition at the bottom of the transition designer (see transition designer image above), and then selecting the desired target state from the Available states to connect drop-down.

Transition

Note: If the Condition of a transition evaluates to false (or all of the conditions of a shared trigger transition evaluate to false), the transition will not occur and all triggers for all the transitions from the state will be rescheduled.

State Machine Terminology
Term Description
State The basic unit that composes a state machine. A state machine can be in one state at any particular time.
Entry Action An activity which is executed when entering the state.
Exit Action An activity which is executed when exiting the state.
Transition A directed relationship between two states which represents the complete response of a state machine to an occurrence of an event of a particular type.
Shared Transition A transition that shares a source state and trigger with one or more transitions but has a unique condition and action.
Trigger A triggering activity that causes a transition to occur.
Condition A constraint which must evaluate to true after the trigger occurs in order for the transition to complete.
Transition Action An activity which is executed when performing a certain transition.
Conditional Transition A transition with an explicit condition.
Self-transition A transition which transits from a state to itself.
Initial State A state which represents the starting point of the state machine.
Final State A state which represents the completion of the state machine.