We've all been there haven't we? You've got a multi-stage workflow, your director has approved it, your manager has approved it, and then **ERROR**
Something goes wrong. Maybe your next approver has left the company since the workflow was started, or there's an erroneous value in your variable that your SharePoint column won't accept.
Either way, you've got into a position where you've already had approval from a director (or anyone) once, you don't really want to have to ask them again.
On long running workflows this can be a real pain. So we introduced a setup that allowed us to "Pick up where we left off" (or were kicked off as the case might have been).
The State Machine is a brilliant action for for these staged workflows that transition through a number of different states and the Switch Action allows us leverage these states. Take the following example:
An item is created, to achieve approval it must go through 3 stages on a State Machine.
- Manager Approval
- Director Approval
- Task to be actioned by individual
Each of these stages is a branch in a State Machine, and after each task has been approved a Status column is updated to represent it's stage.
- Manager Approval - Status = "Approved by Manager"
- Director Approval - Status = "Approved by Director"
- Task to be actioned by individual - Status = "Ready for Action"
The status is updated immediately after the task completes and then the State Machine changes state to the next branch.
Item with ID = 101 is submitted and the approval workflow starts, the manager approves it immediately and then a month later the Director approves is, however, in that month, the user listed in the Item as the person to complete Stage 3 has left the company. So when Stage 3 goes to assign it's task, the workflow fails because the user does not exist in AD.
Enter the Switch!
When we designed our workflow, we created an additional branch on our State Machine called "Status Check" The state machine is set to go to this branch first. In this branch we have a Switch which will check the status column of our item and look for one of "Approved by Manager", "Approved by Director", "Ready for Action" or "Other". Each branch of the Switch has a Change State action that will send the workflow off to the required branch in the State Machine.
So when our item is updated with a new user to "action" and the workflow is restarted, in the case of Item 101, the status is "Approved by Director". The Switch identifies this status and the Change State action is set to send the workflow straight to the "Task to be Actioned by Individual" state. Thus the workflow "Picks up where it left off".
The main downside we have from this is that we are left with 2 workflow instances for an item in order to prove the audit trail of the item, however, the full story is there to see.