Best practice: State machine workflows

This topic is targeted to beginner users of Nintex for Office 365.

A state machine workflow is used when actions within a workflow need to be repeated by multiple parties and workflow advancement is dependent on the outcome. Each state contains actions that execute when the workflow is in that state. The workflow moves between states until it is instructed to exit the state machine.

Scenario: Advertisement creation process

The graphics team needs to approve the artwork, the marketing department needs to approve the artwork and content and the CEO needs to approve the entire advertisement. If the marketing department rejects the artwork, the artwork returns to the graphics department. If the CEO rejects the advertisement then it returns to the marketing department.

Best practice:

To end a state machine workflow, ensure that the Exit state machine setting is specified in the Set next state drop-down list. If you end the workflow with another action or setting, publishing errors will occur.

Example: Advertisement creation process

This example uses the following workflow actions.

State Machine

Assign a task

Set Next State

Send an Email

To build the workflow, follow these steps:

  1. Create a workflow

  2. Add a State Machine action and configure three states

  3. Add an Assign a task action below each state

  4. Graphics team state: Assign a task - Rejected or Approved

  5. Set marketing department state

  6. Set CEO approval state

Create a workflow

  1. Click on the list where the workflow is to appear and then select the List tab in the Ribbon.

  2. Select Nintex Workflow and then Create a Workflow in Nintex Workflow.

  3. Select the Blank template and click Create.

    The Nintex Workflow designer opens.

Add a State Machine action and configure three states

  1. From the Actions toolbox, drag and drop the State Machine action to a drop zone () in the design canvas.

  2. Double-click the action, select Configure from the context menu, and then enter the states for this state machine as follows:

    1. State 1: Enter Graphics Team.

    2. State 2: Enter Marketing Department.

    3. Click Add State.

    4. State 3: Type CEO Approval.

    5. Choose the state that this state machine will start in: Select Graphics Team as shown in the following example.

  3. Save and close the action.

The workflow should appear as shown in the following image.

Add an Assign a task action below each state

In the design canvas, drag and drop the Assign a task action below each state, and configure the action with relevant user information from your environment.

Graphics team state: Assign a task - Rejected or Approved

If the advertisement is rejected from the Graphics Team, an email is sent to the initiator to end the workflow.

  1. Drag and drop the Send and Email action to the Assign a task – Rejected branch.

  2. Configure the Send and Email action to email the initiator about the outcome as follows.

    1. Open the Set Next State action below the Send and Email action.

    2. In the configuration dialog, select the Next state as End State Machine. If the advertisement is approved, a Set Next State workflow action directs the workflow to the Marketing Department state.

    3. Select a Set Next State action on the Assign a task – Approved branch.

    4. Configure the action: In the Set next state drop-down, select Marketing Department.

Note: To end a state machine, always use the Set Next State action. Using any other action, for example, the Terminate Current Workflow action, can cause any number of random errors.

Set marketing department state

  1. Drag and drop the Set Next State workflow action to the Assign a task - Rejected branch.

  2. Configure the action: In the Set next state setting, select Graphics Team.

  3. Drag and drop another Set Next State action onto the Assign a task – Approved branch.

  4. Configure the action: In the next Set next state setting, select CEO Approval.

Note: You can change to a state from any other – states do not have to be directly next to each other.

Set CEO approval state

  1. Drag and drop the first Set Next State workflow action to the Assign a task - Rejected branch.

  2. Configure the action: In the Set next state drop-down, select Marketing Department.

    If the advertisement is approved by the CEO, an email is sent to the initiator of the workflow and the state machine will be ended.

  3. Drag and drop the second Send an Email action to the Assign a task - Approved branch.

  4. Configure the Send an Email action to send an email to the initiator.

  5. Select a Set Next State workflow action and place it below the Send an Email action.

  6. Configure the action: In the Set next state drop-down, select Exit state machine.

Note: If required, the workflow can continue on to other actions after the state machine is ended.

The workflow should look similar to the following example.

For information on safeguarding the performance of your workflow, see Best practice: Prevent excessive looping iterations.

Related information

Configuring actions