cancel
Showing results for 
Search instead for 
Did you mean: 
sergeluca

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 :

val

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)

statemachine

 

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

 

statemachinebranch

 

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 :

Timeoutsecretariat2

 

So you get this :

 

Timeoutsecretariat

 

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 ?   ;-).

 

bossapprove

 

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).

dountil_empty

 

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.

Comments
About the Author
  • Experienced Consultant with a demonstrated history of working in the information technology and services industry. Skilled in Office 365, Azure, SharePoint Online, PowerShell, Nintex, K2, SharePoint Designer workflow automation, PowerApps, Microsoft Flow, PowerShell, Active Directory, Operating Systems, Networking, and JavaScript. Strong consulting professional with a Bachelor of Engineering (B.E.) focused in Information Technology from Mumbai University.
  • I am a Microsoft Business Applications MVP and a Senior Manager at EY. I am a technology enthusiast and problem solver. I work/speak/blog/Vlog on Microsoft technology, including Office 365, Power Apps, Power Automate, SharePoint, and Teams Etc. I am helping global clients on Power Platform adoption and empowering them with Power Platform possibilities, capabilities, and easiness. I am a leader of the Houston Power Platform User Group and Power Automate community superuser. I love traveling , exploring new places, and meeting people from different cultures.
  • Read more about me and my achievements at: https://ganeshsanapblogs.wordpress.com/about MCT | SharePoint, Microsoft 365 and Power Platform Consultant | Contributor on SharePoint StackExchange, MSFT Techcommunity
  • Encodian Owner / Founder - Ex Microsoft Consulting Services - Architect / Developer - 20 years in SharePoint - PowerPlatform Fan
  • Founder of SKILLFUL SARDINE, a company focused on productivity and the Power Platform. You can find me on LinkedIn: https://linkedin.com/in/manueltgomes and twitter http://twitter.com/manueltgomes. I also write at https://www.manueltgomes.com, so if you want some Power Automate, SharePoint or Power Apps content I'm your guy 🙂
  • I am the Owner/Principal Architect at Don't Pa..Panic Consulting. I've been working in the information technology industry for over 30 years, and have played key roles in several enterprise SharePoint architectural design review, Intranet deployment, application development, and migration projects. I've been a Microsoft Most Valuable Professional (MVP) 15 consecutive years and am also a Microsoft Certified SharePoint Masters (MCSM) since 2013.
  • Big fan of Power Platform technologies and implemented many solutions.
  • Passionate #Programmer #SharePoint #SPFx #M365 #Power Platform| Microsoft MVP | SharePoint StackOverflow, Github, PnP contributor
  • Web site – https://kamdaryash.wordpress.com Youtube channel - https://www.youtube.com/channel/UCM149rFkLNgerSvgDVeYTZQ/