Last week I was wrong when I said You only need one template to get started.
There is actually a second template that is useful when you create a new flow. The State Machine workflow. My previous posts about state machines focused on running a flow multiple times and handling the multiple runs of the process. In this post however I will move the process control inside the flow and I will only start my flow process once.
In this post I will explain how the new template works.
I only want to run one process for each document that is uploaded to a SharePoint library. Once uploaded the document will go through 3 phases. In business processes you might need more phases, but for simplicity reasons I’ve only created 3 phases. Feel free to extend the flow once you used this template by added more status values.
The flow is going to run until it is completed. This is controlled by a variable called status. You could also create a document with a status field but why would you want to pollute your document libraries with status fields. That is so SharePoint Designer like. Do you remember the status fields on your libraries?
Then the switch includes a value for the status field for each phase of the process. In my case I’m using the following 4 status values:
- New Document
- Process Document
- Completing
- Completed
Did I make a mistake? Only 3 status values in the switch. That is correct. The completed status will not do anything. Anything that needs to be done before the end of the flow needs to be done within the Completing phase. Completed will only end the flow. If at any time you want to terminate the flow you could simply set the status variable to Completed or Completing and the flow will end.
Within each phase of the process I’ve added a scope box. this is where you can add the actions that are needed in the process. Each scope box is followed by a state change. In real processes you might have to make slight adjustments here. Imagine if the next phase depends on the value of a variable or the status of the process or maybe if a document was approved or rejected. So you would likely have some conditions around the setting of the status variable .
Ok, this is great! But it gets better. Have a look at my flow run history:
You can see the different phases of each process simply by stepping through the do until.
Ok, that is the basics out of the way. How would we use this template.
Imagine if you had a process that requires multiple people to review and approve a document. Each approval stage could have its own branch within the state machine. After my post earlier this week about invoices handling I might as well take that as an example.
An invoice is approved by multiple people.
- Department manager
- Finance Director
- Staff member requesting order
As the process is approved or rejected by the different people you might have to switch between people. Traditionally this could end up in a spaghetti alike process where you don’t know how many times each person will review the invoice. By creating a separate branch for each of the approvals you can see in the flow run history what happened with the invoice throughout its life within your organisation.
You can now find the State Machine template in Microsoft Flow.
[…] state machines in Flows, will help to run a single flow with a state machine alike process and the template for the state machine can also help you. Of course, Serge Luca’s Flow Controller is beating all of these state […]