Power Automate: Error Handling on multiple flows REUSABLY | Try Catch | Send errors in Teams Message

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
your flows are going to fail and that's fine we all go through it but you need to be notified before your users find out we're going to show you how to handle errors for you and for larger teams so the right person gets notified without getting a giant mess of emails I have a flow here so when a new instructor is hired I have a bunch of steps that start the onboarding process it doesn't really matter the details the point is all three of these could fail to catch all of their errors what we want to do is wrap this entire thing in an action and an action called a scope now I like to name these a short summary of what all the steps inside of it are so in this case onboard new hire and then I'm going to take all these steps and move them inside next I need another scope so if anything inside of here fails we get the message so I'm going to add an action called scope again and I'm going to name it handle errors and I'm going to add a compose action you don't need to do this step just because I want to show you something if I had compose in this case I know that my scope is called scope underscore onboard new higher each underscore is a space and one more key step for all this to work is if we open up settings and we open up the run after we don't want it on is successful we want it on has failed or has timed out if I copy and paste this URL into another window I can see previous flow runs so I'm going to open a previous one that I know failed and I'm going to rerun this just so you can see the results and if I take all of the content from here and just throw it into Visual Studio code I get this nice Json that says status equals failed and then error. message the provided host name could not be resolved well obviously 2 M's is not a real URL but if we keep scrolling we see that my compose never got reached and the status is skipped so we don't want to show this one we want to filter down to only this one where the statuses failed to do the filter we're going to use the filter action so if we come over here and I'm going to do plus add an action and type in filter select it and then the source is going to be from the previous composed so we can simply copy that and paste that into the from and then we want to select the item status field so if we just type in item status and then all we need to do is make it so it is equal to the word failed it could also time out so if we click on edit in advanced mode Let's select all of this plop it back into visual studio and do or let's also do timed out the final expression looks like that let's copy it and then paste it into our expression here calling this failed actions and then let's delete this previous composed cuz it's of no use and then let's rerun it and if we open that up we see that we only have the items we care about that are failing we know what actions are failing but let's also find the exact URL link so that way a developer can just pop in the URL and find the exact run-of the flow that failed to do that we have some helpful functions I'm going to come in here add a compose you don't have to to do this step this is just to show what's in here if I go into here and select the expression there's an expression called workflow so if I select that one and then add it here and save rerunning this is going to give us a lot of interesting information about our flow if we open this we're going to see that there's just a treasure of insights such as here is our flow name for instance here's our environment name I'm going to select that one and then here is our run name and you're going to see these as something very familiar you may have seen before if we look at our URL up here I'm going to paste that into here look our run name is just that and then let's see if our environment name appears later and yeah there it is so we can use these properties to build the URL so we can easily find this failed flow run if I hop back into here and do a really long expression like this here's the expression you can literally copy it verbatim paste into your environment and it'll work I put this in the description and I'm going to call this flow run URL and if I reun it and let's open that up we have our URL perfect and we know which actions are failing let's go notify the right people I prefer not to send emails and on the development teams I've been in if one flow fails a ton everyone's going to be blasted with emails on the dev teams I've ran we've always used two channels one is called errors from flows and then another was production errors from flows and this is the one everyone subscribes to so all our Dev and uat errors go here and all the critical ones here the action we're going to use here for this is called post a message in a chat or Channel create your connection and let's select Channel and here let's select our team and then let's select our errors from flow's Channel and here you can name it whatever you want in this case error reported in flow and then I like to toggle the code View and in here we can put an href and inside of it the link is going to be our compos flow run URL and I'm going to put the name of the flow which is start onboarding process and then closing a tag and then I also like to give it a little Pizzazz so I'm going to style it up and add a little inline CSS that says font style equals italic you don't have to add that unless you're fun and then I'm going to add a break for a new line and then in here let's go just dump out our whole failed actions click save and let's rerun this to see what we're dealing with we open up our teams channel here now we get this message in our teams and then here is our URL link which takes us nicely to the exact failed flow so we don't have to look for it now let's back it up obviously we can make this prettier but no matter how pretty we make this developers are going to ignore it because whose responsibility is this it's the reason why in CPR you have to point to someone and say call 911 instead of saying call 911 this four each isn't necessary we're going to get rid of it in a second but first let's tag people if we select get app mention token for a user and then we just have to type in their name we just put in their email here and then inside of here we can put new line do line Brak and please look into it and then let's select their at mention here click save and let's move this out of the loop and then delete this cuz we're going to change this up in in a second but are you noticing that this is getting kind of long and almost all of our main flows should have this aor handling so are we going to repeat this in all of our flows no one flow should do all of the air handling and all of our other flows should just be using that one flow so let's back it up I'm going to come in here and then let's click into Solutions and I hope you made your flow in a solution to begin with if you didn't make your flow on a solution come up here into new solution and make one check out my deployments video if you need more information about what a solution is I'm going to go into one of my existing ones and I'm going to add my existing flow that's right here and I'm going to make a brand new flow and I'm going to call it air handler Notifier I'm going to select manual trigger and click create here's our new flow and then here are some of the steps from the previous flow so in this one what information do we want to pass into this flow the first one is what is the flow name the name of the flow that just failed so I'm going to ask it what is your flow called and if this isn't making sense just follow me for a second it will let's also put person to notify who should we notify what is the URL to this flow and of course our flow message we can't save this for now we need to add something else to it so I'm just going to put a compose just so we can make this savable I'm just going to write the word test click save all right let's start moving code so I don't need this compose anymore and I'm going to copy this this action and then click plus and paste it into here and I'm not going to copy the failed actions because that's still the responsibility of the other flow to figure out what the error is but I will take this token mention token because again our air handler is going to do all of the team stuff and then let's snag that and then copy it into here and we're going to fix all this in a second first we don't need this because our flow URL is passed into here and then get at mention we can get it dynamically from the person to notify and let's do one more called environment ID you could also figure this out from the flow URL but let's just keep it simple all right now let's make sure we're even sending it to the right channel so if we open this up right now we have Channel but we can enter a custom value and dynamically choose which one so if I sit here and type in errors from flows and I click save and I'm going to get rid of this outputs because I know it's going to crash and then and then watch this if I go into here and we could start deleting all these actions from our original flow because we're going to use a different action called child flow and select run a child flow pick our flow error Handler Notifier it's going to ask for thing well here's the name of the flow who do we want to notify just put someone's email what is the link to the flow run well that's just this compose here for flow message I'm going to hit this expression I'm going to type in string because I need to turn that filter action into just text and then inside of Dynamic content let's do just body click add and then I we know how to get the environment ID it's the same thing as from here where if we select the function expression and then type in workflow tags environment name click add hit save oh and I always forget this step we need to add a response action and there's one more step is just a child flow thing run only users means whoever is using your flow all of your connections emails whatever run it under their credential so their permissions but with child flows you can't do that you have to pick who it's going to run under which is good you usually want to run it under Systema or whoever has the most permissions save that and then now I should be able to save it if I go into my flow run here I see that my Notifier is failing I'll explain what that is right here and this is baffling I typed in errors from flows so if we look here at the code view code that's running in the background says error reported and flow BL BL blah I know I made all this and then Channel ID errors from flows that looks right no no no no this is supposed to be a goid a unique ID I'll show you what I'm talking about if I go here and I exit this and I select add channel from the dropdown errors from flows is what it shows me here but if I look in the code view my channel ID is this gobbledygook and then if I switch it up and then go to production errors and then look at the code view the changed just a little bit so what we can do is we can copy this Channel goid or ID and we're going to create a new compose where we're just going to store our production channels ID and then our general errors Channel ID so I'm calling the first one production teams Channel and let's call the other one General errors teams Channel you're going to have to open the teams action again to snag the channel ID for the other channel now I've added one more compose here which is the environment ID of the production environment how did I find that if you navigate up here to your Dev environment here I have 65 DD something and then if I switch environments this changed as well now again I don't recommend you using this hardcoded guid because it's a little confusing I think it's best to use environment variables and then put in the URL of your production Dev environment but for this example let's stick with it and then let's go down here and post message and instead of Channel we're going to add a custom value and we're going to use an Express so in here you do if the environment ID that's passed into the child flow is equal to the production environment ID that we pasted in earlier well if it's the production one then send it to the production team's Channel ID however if it's not the production environment then send it to the general teams Channel and if we look into our teams Channel it looks fine except again our airor message is hideous so let's convert it into a nice table we can select the action convert HTML table and inside of it we have to first put our flow message into Json because it won't accept just text string and then next we select the columns as custom cuz we're going to side our columns let's call the first one action and then the value what's what's the name of the action if we look into it this is an example item and first we have to pick item name and then we have to pick our message if we open that up we our message is under the error node so we have to do item error and then message if you use a lot of HTTP actions sometimes the error message won't be under the error. message so it'll be under output body error and then message so I like to do the concat expression so concat just combines two texts together so in this case no matter where the error appears in either of them it's going to be shown here and then the last step is just hop into our teams message and then we want to put in the flow URL cuz that was missing we also want to Output the flow name and then we want to underneath that put our HTML table that that we just made and then the last step is obviously let's go tag the person that needs to be notified and then if we run this again and now I'm going to hop into my onboarding process flow not the child flow because this one's going to call it and then this one failed I already heard a ding we hop into here workflow mentioned you errors from flows and awesome I get this nice table of the action exactly what went wrong and then if I want to dive deeper into it I can click it and then go investigate and see oh it's it's this guy that's failing and what I've usually had Dev teams do is put a thumbs up to say that they've seen the issue and then a heart if they've resolved it or they can just come up here and click reply and just let us know what's happening and if you don't see an emoji here it's convenient for you because you can go track down to who needs to take care of it and what's not getting done because what's the point of reporting all your errors if no one's taking care of it thank you for watching and big thanks to resid orani who originally had a great video laying the groundwork for this on error handling if you want to work on bigger projects and use best practices like this to manage larger Enterprise Power Platform tools check out my video on Solutions and deployments it's playing next
Info
Channel: Untethered 365
Views: 2,119
Rating: undefined out of 5
Keywords:
Id: zJEi5IaTgdY
Channel Id: undefined
Length: 18min 20sec (1100 seconds)
Published: Sun Feb 25 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.