Showing results for 
Search instead for 
Did you mean: 

Simulate state machines with Microsoft Flow

Most workflow engines & tools I know (Nintex, K2, DataPolis, .Net Workflow) support state machines; at some point your workflow is so complex that you really really need it. I’m a very strong supporter of state machines, but my favorite tool, Microsoft Flow doesn’t support it (yet?). Only sequential workflow is supported so far.


In this blog post, I will illustrate how I solved this specific issue and I believe this could become a pattern for your future flows.


Here is the (simplified) problem :

A use creates a document in SharePoint. This document must be validated by a person called “Val”;  when Val has validated the document, it must be validated by the “secretariat”; when this is done, it must be validated by the “Boss”; then the document will be signed by the boss (electronic signature) , transformed into PDF and published to external users. Of course the boss can reject the document and send it to the secretariat or to val; Val can also reject the document.


Basically the workflow looks like this :


Good luck to create this with Microsoft Flow! Mind you, you might end up creating plenty of not maintainable loops, conditions, approval and you will scratch your head (as I did). And what if you don’t just have 3 approval levels, but 10 or 15..or 100 (…just kidding) ?


When you are desperate you become creative and you start thinking out of the box:

Here is what I did :

  • create a loop
  • create a switch
  • each branch of the switch is a state
  • specify where you come from and where you want to go
  • in the loop specify how you exit the loop

That’s it : – )


Here is the whole implementation (click to zoom)



Here is the detail of a specific state (click to enlarge) :




You can extend each branch (state) if needed by managing the timeout : if the Secretariat doesn’t react on time you can ask it to approve again :



So you get this :




Now I know you next question : how does the system know that when the Boss rejects the document, the request must go to Val or to the secretariat ?


Indeed in the approval form, we only have 2 buttons so far : approve or reject. I know that custom forms will be available in the future, but in the meantime we need to rely on the comment box in the approval form : if the boss types “VAL” or “val” or “V”, the flow will go to VAL, otherwise it will go to the secretariat. He can even type V or Val followed by a comment. This is totally acceptable until custom forms are made available and I believe this is super important (are you listening Flow team ?   ;-).




One of the downside of this approach you will face with this approach is that the until loop is opaque when the Flow is running, you don’t see what’s going on (please Flow team, fix this asap).



However you can still see the current flow state by storing in a custom “status” column in your SharePoint List or Document library. And if you want more (history, statistics, analytics, check one of my previous blog post “Flow approval escalation with analytics“).


In summary: each state become a branch in a switch. This is simple, easy to implement, easy to maintain, it scales and it works in the current implementation of Microsoft Flow. This approach also scales because can can easily add many states (or branches) and each branch can also be implemented as a Service Flow (nested Flow) if needed.


thanks! there go my plans for moving from spd workflows to flow.  are ther user voices where i can vote on the issues noted here (state machine and forms)?

Hi Serge,


Great article, super easy to follow! I found this through the Flow blog that was created off your post. I've been doing this as well, to bypass the 30 day flow run timeout limitation.


One of the things to be aware of is that the number of states has considerable impact on the loadtime for the flow editing page. One large process I had included over 9 states, with some states requiring multiple parallel and sequential actions and approvals, and catches for errors/timeouts, and editing it was quite frustrating. So if you have a really complex process end-to-end, there could be benefit in triggering sub-flows in each state using HTTP, and containing the actions for that state in the sub-flow.

Thank you very much for this all information.


Could you kindly tell me or sharing the Variables images (In pink)? Please!

I hope that SPD will not decommissioned before we have state machine feature in Flow

Meet Our Blog Authors
  • Working daily with Microsoft Cloud to deliver the needs of my company, my customers and various Microsoft communities and forums. | Office 365 | Flow | PowerShell | PowerApps | SharePoint |
  • Co-founder of, Office 365 and SharePoint expert. Passionate about design and development of easy to use, convenient and flexible products.
  • Microsoft Business Apps MVP. Owner of ThriveFast, an Office 365 consulting company.
  • 7x Microsoft Business Solutions MVP (CRM)
  • I'm keen in MS technologies, SharePoint, Office 365 and development for them
  • Daniel is a Business Productivity Consultant & Microsoft Business Solutions MVP who is very enthusiastic about all things Office 365, Microsoft Flow, PowerApps, Azure & SharePoint (Online). Since the preview, Daniel has been working with Microsoft Flow and later on with Microsoft PowerApps. That led to him being awarded an MVP Award for Business Solutions. He loves to blog, present and evangelize about improving productivity in the modern workspace with these amazing tools!
  • Michelle is an Office 365 solution architect in Twin Cities, MN. She has been delivering business collaboration solutions for years with her focus on SharePoint and Office 365. Michelle is a recent board member of the Minnesota Office 365 User Group and has been a member of the SharePoint community since 2009. She is a frequent speaker at MNSPUG and SharePoint Saturday and co-chaired the Legal SharePoint User Group for 4 years. Her most frequent projects have involved rolling out a large deployment of Office 365, SharePoint Online intranet, build of a "CHAMPS" Office 365 user adoption program and most recently, SharePoint On-Premise to Online Migration. Michelle is very excited about cloud technology as it is shifting her IT Pro focus to collaboration strategy and technical adoption.
  • I'm a Microsoft Office Servers and Services MVP with a special interest in SharePoint, Office 365, Microsoft Flow, Microsoft Teams and PowerApps. I work at Triad Group Plc (
  • Passionate #Programmer #SharePoint #SPFx #Office365 #MSFlow | C-sharpCorner MVP | SharePoint StackOverflow, Github, PnP contributor