The Nintex Workflow State Machine is a very useful piece of functionality. Not only is it a great enhancement to workflow design, it also improves maintenance of a workflow in the future.
Your workflow logic may require you to jump between difference levels business logic. An example of this, is if you have several levels of synchronous approvals. Having Request Approval actions one after the other is one option. But one of your requirements may be, that if the 2nd level approval rejects an approval, that it then goes back to the previous level of approval.
You could build the logic using the Loop action, but it would be messy and later on, it would be hard to maintain.
I have 3 levels of approval. At the first level, if the approval is rejected, I want the initiator notified and the workflow to end. If they approve, then I want the workflow to continue to the 2nd level approval. If the 2nd level approval is rejected, it should go back to the 1st level approval. The 3rd level approval, if rejected, should go back to the 2nd level approval.
Create a new workflow, and add a State Machine action to it.
By default, the State Machine will have 2 states named "State 1" and "State 2". a State Machine MUST have atleast 2 states.
As we are looking at a solution that will have 3 levels of approvals, you need to first open the configuration of the State Machine. Here, you can update state names and add new states.
If you then go into the configuration window for the State Machine, you need to select the Initial State. This is the first state of the State Machine that the workflow will go into.
For the 1st approval level state, we send out an approval via the Request Approval. If the approver, which I have set as the initiator just for testing, approves the task, then we use the Change State action to change to the 2nd Level Approval state.
If they reject the task, then we use a Send Notification action to notify the Initiator, and then we add a Change State action to change to "End State Machine".
The Level 1 Approval state looks like this :
This is the beginning of our state machine. Now we build the logic for the other 2 levels of approval. The Level 2 Approval state simply sends another Request Approval and if it's approved, changes state to Level 3 Approval state, and if rejected, it changes state back to Level 1 Approval state.
Changing states only occurs at the end of the current state.
This is a very important piece of information. This means, that if you have a Change State action, followed by other actions, those actions will execute before any state change.
Above, I have added a Query List action, a For Each action and a Log in the History List, all after the Change State action that changes to the Level 2 Approval state. even though the Change State action is above those action, behind the scenes, it simply sets a flag to tell the workflow that at the end of the current state, we want to jump to the Level 2 Approval state.
I wanted to mention this, in case anyone finds themselves in a situation where they think the state change should happen instantly, it won't. It will only happen at the end of the current state.
Download State Machine Workflow