Using Try, Catch and Finally in Microsoft Flow.

 Hello Guys,

Today we are going to learn how to implement Exception Handling in Microsoft Flow. If you are new to MS Flow then please read my this blog.



Do follow us to know more about Dynamics and Power Platform. Also if you like our blog then please comment and share this blog with your friends.

As being a Software Developer, we all know about Exception handling as we all have implemented in various programming languages like C#, Java, Python etc. This mechanism is used for handling errors which occurs during the program execution using Try, Catch and Finally statements.

While running a flow we have faced many situation where our Flow fails due to some error and because of that some steps of flows are getting skipped. We want some mechanism here also where we can handle errors and make the flow run successfully.

To implement Try, Catch and Finally in MS Flow we have the concept of Scope. Scope is similar to group actions which can be collapsed to make large workflow looking smaller and easier to read. In other words it is collection of steps or actions. If any error occurs inside a Scope, the whole Scope is errored. So they clearly show how the flow flows.

To understand Scope we will be creating one flow which will be fetching Employee's data(shown below) and sending them as JSON Response.



Navigate to https://us.flow.microsoft.com and select your environment.

Click on Create and select Instant Flow. Configure it as below and click on create.




Now add a new step and initialize two variables as shown below.



Now add new step and search for Scope. Rename it to "Try" as shown below.



Click on Add an action inside the Try Scope. Search for List records and configure it as below.



Click on add new action below the above step. Search for Parse JSON and configure it as below.



Here in above step schema is depending on your entity. So create it accordingly.

Add new action and search select step and configure it as below.



Here we are mapping the CRM records into JSON. Add an action below the above step. Select Apply each and configure it as below.



Inside the apply each step add an action i.e. Append to an Array and configure it as below.




Now add an action below the Try Scope and add one more scope. Rename it as "Catch". 



Also click on Configure Run after and select below option. Click on Done.



Now inside the Catch Scope add an action i.e. set variable and configure it as below.



Add new action below the above action i.e. Respond to Power app or flow and configure it as below.



Now below the Catch Scope add one more scope. Rename it as Finally, and configure its Run after as below.



Inside the catch scope add and action i.e. Respond to Power app or flow and configure it as below.



Save the flow and Test it.



As you can see in above flow run test, Catch Scope is skipped as our flow ran successfully.

Hope it helps...


Comments

Popular posts from this blog

Read Only Sub Grid & Editable Sub grid in Dynamics 365

Understanding Sales Process in D365.

Understanding Business Unit in Dynamics 365.