Error Handling in Power Automate flows | Try Catch Scope Action

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
getting instant notifications when your power automate flows have failed because of an error is extremely critical to maintaining business continuity also the notification must include the action which has failed and the reason for its failure in this video I will focus on the configure run after feature which is available for every action and flow that helps us to isolate errors so let's check it out in action [Music] 28 day run history for the flow here I can visualize which of my flow runs have failed I do not get details around why they have failed I have to select my flow run and in the run view is where it gives me the error details plus the analytics for a flow there is a tab for errors this will give us a report of all the errors that have occurred in the last 30 days it will give you the action that is causing the error the status code the error count as to how many times that specific error has occurred what was the last occurrence of the error and what's the error message now these patterns of heading to the Run history or the analytics are actions that the owner has to take periodically these are not proactive actions one of the things that power automate does to proactively notify an owner is that it sends out an email that states your flows have failed lists out which flows have failed and how many times they have failed it does not give us instant notification of failures it does not notify what the error message is which action on the flow is causing that error also if your flow has been consistently failing power automate would automatically go ahead and disable it I have a simple flow that triggers manually and in this flow I will add a very simple compose action in which I will write an expression 1 divided by 0. I'll go ahead and save this flow and I will test this flow manually now once this flow runs it says that the flow has failed I can see which specific action has failed it has this red indicator next to the action to notify the user that when this flow ran there was an error and here's the reason for the error so to do that I will add a new Step here to send an email to the owner of the floor the subject and in the body I can state that my flow has failed now this action send an email I would like to configure the run after for this if my compose action has failed so I'll click done this time if I run the flow my flow ran successfully the reason is because even though this action failed I was able to catch the error and here is the email notification that I have received one thing I would like to know is what is the reason this flow has failed now in power automate we have expressions one of the expression functions is called as actions it returns an actions output at runtime all you have to do for this specific function is pass the name of your action in this case my action is called compose so right on the body of the email I will head over to expression and write the expression actions of in single quotes compose I'll click ok Let's test this flow the flow has run successfully if I look at the email that I have received I get this Json object which is the output of that actions function to grab the error message it is in a property called error and within that there's a property called message in the body of the email the expression that I will use is actions of compose question mark error question mark message click ok another step that I will recommend to take is to ensure that you terminate the flow as field so let's test this flow the flow has run this time because of the terminate action it says the flow run has failed we caught that exception we got the error message of that exception which we have now sent out in the notification email to the owner of the flow the floor owner can clearly see the reason why the compose action has failed and the reason is attempted to divide an integer value by zero a link back to that specific floor run where I am sending the email I will change to code View I'll add anchor tag where the href would be the link to the flow run I will call this open the flow run to take action now how do I get the link to this specific flow run for that we have an expression called workflow that has all the details that we need to formulate the URL for the flow run I already have that expression ready so I will simply go and paste it in here in the expression dialog if I run my flow run has failed I receive my email which includes all the details of flow owner needs and a link directly to that specific floran where that error occurred I have plenty of actions in my flow now handling errors for each of these specific actions by defining configure run after is not a viable solution so to handle a group of actions together we have an action and flow called scope and in the scope action I can simply add all my actions in the scope action you cannot initialize variables so these actions would have to be outside of a scope I have moved all my actions into a scope action which I can rename and here we'll try and map to the standard exception handling protocols which is try catch so this scope I have renamed as try so think about this as my try block when I'm trying certain actions and after the try block I will add another scope that I will rename here to catch and this action will only run if any of the actions in the try block have failed we have other options here as well that could be equally important for example timed out maybe my flow is calling an API and the API is not responding in a timely manner so ideally you would want to catch both scenarios that have failed or scenarios in which my actions have potentially timed out so I'll pick these options and I will click done in the catch block I will add a data operation action now to get the details of what happened to those actions inside the try block we have an expression function called result and to this I will give the name of my scoped action and this would return an array of all the objects all the inputs and outputs from each of the top level actions inside my scope action I am only interested in those actions and the try block that have failed or there was a timeout I will use the Expression result of in single quotes try and for my condition I will head over to expression item off status if this is equal to failed but if you also want to look at the ones that are timed out you would need to go to edit an advanced mode which gives me the full expression here go ahead and copy this I am leveraging a notepad so I've just pasted that expression here right after at I'll put an or condition the status is timed out and I will close the or function this is my expression so I'll simply paste it here next use the data operation action create HTML table the from property would be the body of filter array this will give me all the details of that Json object coming from the result action if you need specific data points I'll go ahead and do that by picking custom I will specify first the action that has failed or timed out I'll call the header action and for the value I'll write the expression item of name I would need the status of that action I will use the expression item of status and the error message item object get the error property and then get the message property then I will send an email so I also want to notify the person who created the item that something has failed apart from the owner of the flow so here I can pick the owner of the flow and then from Dynamic content pick the email address of the user who created that item body of the email put that HTML table output we also want to put the link to the flow run so I will go to code View and this is the same expression I showed earlier to get the flow run I will also add styling for that HTML table and after the send an email action I will ensure that I terminate this flow with the status as failed let's see what happens when this flow runs the flow has failed one of the actions on the try block has failed in my scenario here the catch scope filter array action we filtered on all that data to only fetch the ones that have failed or timed out we created the HTML table and notified the owner of the flow and the person who created that item the set variable action has failed because it was of Ty Boolean and the value provided was of type integer I have the link to my flow run so I can get to that specific flow run look at the action that has failed and then go ahead and make the fix when you start creating your flows by default we do not get the error handling capabilities and we need to plug in all that logic now if an organization can create a flow template that comes with default error handling for example in this scenario a flow where we have the try block ready to plug in your actions the catch block Logic for failure timeout HTML table creation sending the email logic is all ready to go I would like to send a copy of this flow to Sarah I'll send this here is the notification email that Sarah has received says Raza has shared a template said I can create a flow based on that template you can see the flow is leveraging the Outlook connector so Sarah is signing into that connection and now Sarah can simply go and start using the flow which already has that pattern ready she can start adding all her actions in here the flow trigger is something that can be changed right now it's a manually triggered flow if Sarah wants to use any of the other trigger actions like when an item is created on the SharePoint list Sarah can do that and then start adding all her actions in the try block the flow that loads data from an Excel file into a SharePoint list the Excel file has some basic information around student names the subject and the score and I have a list in SharePoint which has Columns of different data types one of them is score which is a column of type number and one of the rules for the score column is that the minimum allowed value is zero now this data is coming in from an Excel file maybe manually typed by certain users and there is a chance of an error for example here the scores are given in negative numbers now if I was to run my flow it has failed and the apply to each action has failed and in here some of the loop actions are successful some of them have failed and the reason is because the score that is provided has that negative value so here's my catch block that should only run if the previous action failed in this case I use the result function and I should be using this on apply to each so I'll enter that exact action name and then the remaining process is the same let's try running this flow the flow has failed the exception was caught the email was sent all it says is that create item failed but it doesn't give me any details about which items have failed or why have they failed and the reason is because the apply to each action is a loop and the way the result action works is it only gives us details of the top level action which is applied to each not the actions within it so in scenarios like this especially knowing that the biggest failure point of this flow could potentially occur when I am creating the item in the SharePoint list I will first initialize a variable I'll call this VAR errors I'll make it of type array and in the apply to each loop I will try and append to that array variable details about the specific item that was being created and it failed so configure run after failed I'll put the first name last name I would like to give my error message that would come from an expression which would be actions of create item error message after this I would like to send an email only and only if there were errors and to do that I'll add a condition and use the length function to check if the length of that array variable is greater than zero if that is the case it means guaranteed there was an exception and all I have to do now is simply send an email to the owner of the flow error loading data into SharePoint for the body of the email I will switch to code View and here use the Expression join to join the data in that array variable and I will join this with a couple of line breaks I can always add the link to the flow run as well and after sending the email I will make sure I fail this flow because there were errors Let's test this flow out the flow run has failed and here is the email that I have received it clearly highlights which items from my Excel file have failed and the reason for the errors if you enjoyed this video then do like comment and subscribe to my YouTube channel and thank you so much for watching
Info
Channel: Reza Dorrani
Views: 74,052
Rating: undefined out of 5
Keywords: power automate error handling, power automate error handling best practices, flow error handling, power automate flow error handling, power automate flow error notification, power automate flow error, error handling, failed flows, flow, power automate, error, exception, flow failure notification, power automate try catch, power automate try catch get error message, error message, reza dorrani, terminate, try catch, scope, power automate error logging, try, catch, configure run after
Id: qLADf8ne5qQ
Channel Id: undefined
Length: 17min 21sec (1041 seconds)
Published: Mon Oct 31 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.