Advanced Error and Exception Handling in Power Automate Desktop - Complete Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
have you ever encountered arrows while running your automation flows don't worry with power automate desktop you can easily handle exceptions and errors securing a smooth and reliable automation we'll dive into two powerful techniques action-based error handling and creating an exception Handler around a group of actions with the mighty unblock arrow in the upcoming tutorial I'll guide you step by step on how to handle exceptions and errors in power automate desktop effectively you will witness firsthand how these techniques can enhance their robustness and reliability of your automation projects a Microsoft most valuable professional let's learn some exception handling in power automate desktop today's data is an Excel sheet the sheet is called error handling and it is an Excel table we have 11 rows where the first ones are a headers row it's number a number B result and status for each one of the rows I want to add number a to number B and print it in result then I want to say success in status but beware we have exceptions in this one here you can see an a down here you can see a b in number B and here is in C we want to not print the results for these ones because we can add an a to a 4. so we want to skip that and then we will have an exception message over here in status and afterward we will handle errors in the system that could be our application let me close this and I placed it on my desktop again please download it once you have that place it on your desktop shift right click copious path I created a brand new power automate desktop flow you should do the same then we'll have a set variable drag it in I will call this one Excel path like this and then the value I'll say Ctrl V I'll delete the quotation marks always use variables for things that can change easily and that could be a path here I want to launch my Excel sheet so I'll find a laurance Excel and drag it in and please please do this exercise with me I promise you you learn 10 times faster if things goes too fast just pause or rewind the video it's designed for that so here I'm opening up the path that is stored in the Excel path that one is up here I will not make the instance visible and I'll click save I want to set the active Excel worksheet because we have plenty of sheets in this Excel book and best practice is to specify it it otherwise it will read the last one active it's our sheet in scope right now but let's imagine that our colleague open up another instance of this book and might have edited a different sheet then we would read an incorrect sheet so always have this set active Excel worksheet then we will opening up the Excel worksheet with the name error handling like this save then we want to read it read from Excel worksheet and here I want to read in the Excel instance that we opened up here I want to read all available values from the worksheet make sure you go into advanced first line of range contains column names the variables produced is called Excel data I could say Excel data numbers for example to describe it a little bit better then I click save again this set active Excel worksheet is very important because it reduces errors in your workflows then I just need to close the Excel so I find a close Excel action and drag it in here for now I will not save it and you can see we close the Excel instance again click save try to run it just to see that we can actually read the data into the Excel data numbers data table go over to the right two variables in case you don't see it it might look like this simply just click this x up here and Excel data numbers double click that and here you can see that we have read our data into a data table that is called Excel data numbers you can see that this is the index of the data table a data table is zero indexed so the first row in the data table after the headers row is index 0 1 2 3 we will use this index a little bit later now click close we want to convert the number A and B of the Excel data table so first I'll have a for each that one will iterate the data table drag it in right after the read from Excel worksheet and before the close Excel the value to iterate that will be the Excel data numbers double click here we will store it into a current item that means that when we iterate we call each one of these rows current item I click save now we can do something with it let's try to convert the number a to a number so I find a convert then you'll find a text to number and drag it in first we want to get into the current item so I click this little X here and say current item and this one is a data row that is each one of the rows in our data table one by one I have a hard bracket then I'll have a single quotation mark and then I write in the headers of the column that I want to look in so for this this will look in the current row and it will find the cell with the header number a then I want to say what variable name should this be stored in so click here I will call this one number a because that's what it is then I click save try to imagine what will happen now so then I can click run it will work because we can convert a text to a number two times but then we get a narrow and Z here it can convert text a into a valid number if I go over here to Excel data numbers that makes sense it could convert this number this guy here but it got stuck here because this one can get converted into a number so here we have an error in our data that is what we used to see from the business side say that you forgot something they put invalid data in like a social security number in the not in the correct format anything that we cannot use by our workflow we can handle this so let me close this the first thing we want to look at is to handle arrows on the Action level that is on each of these actions we can handle potential errors try to double click it then go to on Arrow here you can see let me just expand it a bit here you can see that what we're doing now is drawing an arrow that is what you see here in the errors list that has the disadvantage right now that the flow is stopping we are not processing the rest of the items so we really wanted to process all the items and then just jump over the ones with invalid data and just lock the status of it first you can click this continue flow run and here you can see that exception handling mode I can choose to go to next action can repeat the action if I want to retry it or go to a label we'll get back to the label I'll choose to go to next action that will be the end here and that means that we go up here and process another row in our data table so here we're just skipping them that's fine for now so try to click save and run it once more you can see that now our flow can run we're only converting it we're not doing anything yet but this could be a system operation that we were doing so what I wanted here was that I want to get notified whenever this exception occurred and I still want my flow to run so let's go create that I'll go into the action again go to on Arrow and let me do this so here I won't in fact a true narrow and then I want to add to a transaction status variable what happened here I can do that by clicking new rule set variable you can see here a new variable is getting initialized called new VAR let's rename it to trends action status and over here we could set that status to something let's call it a business exception because this is not really something to do with our robot here this is something to do with the data that we're getting It's Perfectly Normal we just need our workflow here to handle it here you can say number a was not in a valid number format like this then I can click save so right now we're throwing the error again but we are logging the status of this transaction to a transaction status variable so let's try it it will stop with the third iteration but we just want to inspect that we're actually getting the transaction status over here we are here you can see it number a was not in an added format what we can do about this is that we can handle these errors that comes from this convert texter number we can put put it in a scope and solve for that accordingly so go up to actions then you'll find in on block error here and drag it in in the start of the for each I will call this one here process process accept shunts like this it works almost the same as an action on Arrow but here we can handle multiple actions let me show you how it works so I'll just save it for now you can see that we have this unblock arrow and I can drag this convert text to number in it that means that if an error is getting thrown here and that's actually what we're doing let me try to open it again go to an error here we can see we throw an arrow each time this convert texture number fails this will get chord by this on block arrow and now we can specify what we want to do what do I want to do here I will I want to jump to the end of this block and continue with the next transaction and yes we will create the log after that so what I will do here is that I'll say continue flow run go to the end of block and this is the end of the on block arrow here so if I click save here now I can run it and yes we are having errors getting thrown here in the convert text to numbers but those ones are getting caught by the unblock arrow and our flow will continue so right now it completed successfully now let's lock the transaction status back to the Excel data numbers data table up here let me open it so I want to lock the status back here to the status I can click close here before that for each we want a helping variable this one we want to keep track of where we are in this Excel data numbers because we're iterating it and we can't find it directly from the current item so here I'll have a set variable I'll drag it in in front of the for each let me move that one over here and this one here I will call it row index and since our data table was zero indexed every data table is we will give it the value 0. then for each iteration of the Excel data numbers we want to add one grid because then our row index will indicate where we are in the for each do this again I click this x because now I've created the row index click to sex row index then move inside the code block that is the percentage signs and say plus one now we are adding 1 to the row index then we can add the status of the transaction so let's just say that right now we're only logging the business exceptions into this transaction status we will also have a success so before this set variable we will have another set variable where do I want to log to well I know I want to log into the Excel data numbers here and I also want to go here I also want to say in what cell do I want to lock the transaction status to well that will be in hard brackets that will be in the row index because that is the current row that I'm in hard bracket end I also want to say go to the status column because then we have defined a cell we have a row index and we have a column name and I can say status like this we could of course also have put in the status index that will be index tree the header is a little bit more stable so what do I need to put in I need to put in the transaction status so I click the sex here so scroll down double click the transaction status and click save I also want to log a success and I can put that up here to the transaction status because if an error occurs here in the convert text to number then we will go to the unblock arrow and handle it and what will happen then then we will go to the end so right after the convert texture number I can have a new set variable I can click this x double click the transaction status and simply just say success click save because we will never get here when an error occurs up here because that way we will end in it or we will go to the end and we will continue so right now we are locking this assessors that is if we can convert this text to a number but we're also logging the business exceptions that is if it's a not a number up here let's try to run it so I'll click run and in case you want more of these please give this video a thumbs up that will really help my channel a lot thank you so we're iterating through each one of these now we can go up to Excel data numbers double click it there you go here we can see that we have a success success we have a business exception here and here of course we haven't done uh number B yet but that will be the same so here we want a business exception number B was not in there how did number format but our business business exception handling works now I go up here Ctrl C to copy it Ctrl V to paste it we have the exact exact same action here with the on Arrow handling you can see that one has this shield down here so let me go into the second one here we want to change this to B this one to be as well you're more than welcome to drag in a new convert texture number and do these things I'm just lazy as an automation developer so I always try to copy paste as much as possible and we also need to change a to B here that's it so now we have the two convert text to numbers here and we have them in the on block arrow now try to run it again and see that we can actually handle business exceptions in both the number a and then the B column then I can move over to Excel data numbers there you go we have now also a business reception when the number B is B so let me click close here we also want to lock the result and that is just number a summarized with number B so I can have another set variable once I've converted these two here where do I want to do that click this X I want to find the Excel data numbers I go up here and again I do the same syntax hard bracket row index hard bracket end hard bracket start and then I want to say where is the result supposed to go well that is supposed to go in the result and what will the result be that will be number A Plus number B so I'll say number a go in here plus I'll find the number P like this we only need percentage sign in the starting at the end so delete these two here and click save now let's try to actually make it work so I will start it here and that's it and if I go over to Excel data numbers you can see that whenever we actually can't add these two together here we have the result and it works let me click close here so we have now handled the exceptions that we can have in the data of course we can make a lot of more checks but this is how to do it you can also have system exceptions that is if a system is down or it's behaving not accordingly to what we expect so let's go create the system exceptions as well go up to actions then I'll find a run application and drag it in here after this variable the first one or just around the launch Excel so we're opening up the applications the same place in the application path I will give the application path this will be the windows calculator the windows calculator is an excellent application to train with here in power automate desktop because it behaves like all other applications and we all have it so don't think that this is too simple for you we will make it work with the calculator and I promise you you can make it work with any application that you want after that here we can see we have a variables produced at process ID now the best practice is since we're not going to use this I'll just untick it and click save now go to your Windows start menu and in fact open up a calculator here click it now this is the application that we want to automate first we want to click a number that will be number a then we want to say plus then we want to click another number that will be number B we want to get the result and drag data out of this application this mimic perfectly what we're doing in a normal process that we read some data from a database or an Excel sheet here we type them in in application and then we get a search result or anything back here so let's go click the first number search for a click UI element in window and we will drag it in here in the convert text to number so here I want to have a UI element I want to say add UI element let's just pick a random number say control and pick the number so here we're just saying number seven we will change that in a little while so I'll say save I don't want to click the seven but I want to click the number a and to fix this selector I go over here to this stack of elements you can see it here click it this is the selected that is the address of the button that we defined which was seven first I want to rename it so I can either right click rename or press f2 let's call this button number a click into that is another best practice always rename your UI elements because in that way you can easily maintain this workflow when you come back to it in the future or your colleague can double click the button number a button this is the address that is the selector click the text editor up here so this is the selector and up here you'll see the parent then you will see child to child to that parent children and here you will have the actual identifier it's saying that we're looking for a button with the ID num 7 button so instead of this seven mark it here say select variable and pig number a now we're using our variable in the selector it's called a dynamic selector then I'll click save I want to do it the same thing with b and I want to click plus and then I want to find the result so we are not using this set variable here let me just delete it and we will create the button number B the same way as we just did the easy thing is not to copy paste it here I think I'll just create it once more add UI element find random numbers but press Ctrl and select number ADM was we go over to UI elements I right click here I will say number B press enter double click to open it pick the text editor up here Mark the number eight select variable and pick number B then we'll click save so now we're clicking number a and number B I want to add them together so another click UI element in here I will add a new UI element I will find the plus here so press Ctrl and pick the plus again this is system work we will create some system errors in a few seconds and I also want to say equal to here so I'll have a click UI element click the drop down add UI element I will press Ctrl and have the equal button here then I click save here you can see my UI elements over here so this process would look something like number plus number equals two so I press a button in my system and then I want to get this result back now you go up to actions and then you'll find an extract data from window drag it in below the four click UI element click the drop down add UI element that one is here press Ctrl pressure Mouse and we will not store it in Excel spreadsheet we will store it in a variable because we're not going to work with it this variable I will call result I will click save so now we're doing the system work we're extracting the data into result and we are logging it as a success if we don't have any exceptions up here if our system fails that could be that the application shuts down or something we haven't handled those errors accordingly right now this calculator is very very stable let me close this application again I'll just go over here to this UI elements I right click rename because I want to tell what's going on I can call this field result and click enter now my my robot is ready to run so I will click run here this will be a longer workflow where we will do system work for each one of these rows except the ones that where we have a system exception those ones we will skip I will Fast Forward here to the end and while I do that please subscribe to the channel if you you want more of these videos see you at the end that's it it looks like it worked perfectly if I close here we can see the last transaction status was success the result is stored in a display is I can double click it here this is the result and it's just because this display is comes from the calculator so let's get rid of that that's just a minor thing before we create the system errors so I click close here I also want to close down the calculator once we're done with it so let's also do that find a terminate process drag it before the close Excel or after doesn't matter and here I can specify what process I want to close in fact I should have let the calculator open so let's go to the start menu open it again because then I can find it here in the process name let me just click cancel here drag it in again and now we have updated this process name these are the active processes on your computer if you scroll down you can find the calculator app here I can click save so now we're closing it I also wanted to get rid of the display is from the result here I can do that very easily by having a get sub text right after we extract data from window so the original text that would be their salt I want to start to get this one here at this position that will be 0 1 2 3 4 5 6 7 8 9 10. the 11th position that will look like this and I want to have whatever comes after the 11th position all of it so I'll say end of text let's store it back to the result variable so I will do like this and click save now we should have did it as the actual number and not the display is I can try to close it again I will run it and let's just fast forward over this just to see that this steps also work that's it and if I go over here you can see that the result is now in the correct format and my application got closed now let's look at the system exceptions with the system exceptions we want to combat things that can go wrong with our application that could be that the application is getting shut down or change State here we will create a system exception that checks for if the application is actually open or it got shut down by a random incident feel free to build on this and expand to your needs so what I will do here is that I'll go up here to my for each we have this convert text number where we check for the business exceptions and in these Five Guys here that is the application work that is where we want to check for system exceptions so we will drag in a nested on block arrow that will surround these ones here go up to actions so here I'll find on block error I'll drag it in after the first convert text to number and here I can say system work exceptions just choose chosen arrow for now we will fix that do you want to network and learn from the best power automate desktop developers then you should join the I love automation Discord Community it's 100 free with more than 7 000 developers your guide and invitation is right up here in the right corner and click save let's drag these five in here so what you do is click here press shift on your keyboard click that and drag it in yeah so that is where we want to check for errors of the system kind what could go wrong here that is if we're trying to click a button and it's not present that could be either because the application has getting shut down or its chain state in either way the easy thing to do would be to open up the application that it will be the solution that we will try most of the times of course that might not work so we only want to try it x times that could be 3 and then we want to continue where we skipped to the next transaction with the system exceptions up here here I just want to stop the process because if the application is not working x times then I don't need to process the next item the next item and the next item so we will create a subflow for that and that is to reuse the component and to make a better overview of this process click subflow here new subflow here I will call this one open app and I'll click save a subflow is just a yeah subflow that you can run from your main then it will run this and jump back to where it came from in the main here I want to have a status off because I want to know if this subflow has ran or not so I'll have a set variable go up to this one here yeah I'll say open app run and this could be true or false here it will be true that is when we start this flow this is just a tracking variable we will use it a little bit later then I want to say well I only come in here if the application if these buttons can't be clicked and that means that I should try to reopen the application X number of times so let's go with a loop drag in a loop here I want to start from one I want to end from 3 and increments by one this is only my preferences that I want to try three times you're more than welcome to try five but it's probably not making sense to try a thousand times because when this system doesn't want to open you might not solve it by trying a thousand times other than putting pressure on your system here in the variables produced we are saving each one of these Loop runs into a loop index that means that the first time we run this Loop index will be one two and three and when we finish it will be four when we continue so I click save here what do I want to put in here well if I come here I definitely want to try to reopen the application so I say run run application put it in here the application path again will be calc actually we could have created a variable for that variables produced I will not have the app process ID I will click save but now we open again we also want to see is this really opened then I can go up to actions and here I will find an if window drag in this if window right after the run application so what do I want to do I want to look at the window UI element click this drop down and we actually created a window that got created automatically when we created the buttons here so choose the window calculator I can see that that is the actual calculator I can double click that so we're checking if this calculator is in fact open if it is then I can exit this subflow and go back to my main workflow to do so I will have an exit Loop and drag it in here so if this is not the case then we will go down here we will try again we will try three times let's say that for some reason this application cannot be opened then we want to lock that into a variable so we can use that information in our flow I'll go over here to actions here I'll find an if and drag it in here so what should my question be that should be if the loop index is equal 4 that means it tried three times it came back here as index four it says now this condition is no longer true I continue so if the loop index equals four then I know that this application cannot be open on find a set variable and I'll have it in here let's lock this message back to our transaction status so I click this X double click the transaction status and here let's call this a system exception and let me repeat a system exception is when something is going wrong with our applications with our systems anything that is not related to the data and here I can see couldn't open Target application then I click save so now I have this one here where I say whenever this runs I set the open app run to True then I know that this flow has ran and I also say if we cannot open the calculator in three attempts then I want to set the transaction status as system exception couldn't open Target application and I also want in fact our main workflow to finish right here so back to main so in the on block arrow here I want to double click so here we're drawing an arrow instead I want to say continue flow run by going to the end in fact I want to retry this whole one we will build that in a little while so whenever we have an arrow here I want to run this subflow called open app so I say new rule run subflow find your subflow called open app here in this drop down now you click save so now we're saying if we Face an arrow here I want to run this subflow and try again and whatever happens I want to move to the end so now we want to handle when we come right here in the workflow we want to say if the transaction status starts with a system exception then we want to handle it accordingly and let's just create two labels this is just to send our workflow to different parts of our workflow when we want it works like this go up to actions and find a label drag in the label in the start of the for each here I want to say process item and this is just a label so I can send my workflow back to this start that means that if I face an arrow here and I'm actually able to open up my application I can send my workflow back here and retry similarly I also want to have an end down here in the end so before the close Excel I want to have a label called end I'll click save so now I can go up here because now I want to ask if my transaction status start starts with system exception so find an if drag it in right after the end and this is where I come whenever we have ran this open app subflow because we defined that up here in the unblock Arrow so the first operand that will be the transaction status go find that click this drop down now I want to say starts with and then I want to say system exception in that way we can combat more than one system exception just make sure you start all your system exceptions with system exception then we'll click save so if we have a system exception then we want to say what do I want to do well I want to log it in the current status of the Excel data numbers let me open it again so I want to log it with let's say it was here number two I want to log a system exception here and then I don't want to process each one of the following because now my system is down for whatever reason so let's find a set variable and let's lock the status first I'll drag in a set variable where do I locked want to lock to we created that one before but let's practice I click click the sex Excel data numbers I want to go into the row that is called row index that was our row identifier and then I want to have a hard bracket status single quotation mark hard bracket like this so now I'm logging into the current row with the cell from the status column so the cross between the current row and the status column what do I want to add I want to click to sex here pick the transaction status click save be aware this is only when we have a system exception and what do I then want to do well I want to stop everything I want to go to the end and close the Excel down here so I just go up to action that was why we created the labels I'll find the go to after the set variable that is important so we can log first and then we go to a label click this drop down find the end and click save let's say that we we get here then I also want to ask is this open app run true because we're also getting here whenever we haven't run this workflow we're also getting here with our workflow so I only want to say if that is actually true that means that we could start up the app again then I want to go back to the process item but only whenever this subflow has Ran So in this if I go up here and then I want to ask another question that is with an else if so I drag in the else if what question do I want to ask now I want to click this little X here I want to find the open app run if that is equal to true and be aware this I just set it to true as a Boolean variable here that's a true volt variable you could set this to yes without these presence and whatever you want so that is just to say if this is really equal to this then we want to do something and this true that comes from the value I gave it here so you can of course give it another value here and ask another question I prefer this method though so if this is true that means that we should start over and I also want to reset this open app run so I want to set it to false so first I'll find a set variable I want to say the open app run set it back to false because I don't want to have it the value in the next run sorry here I just say false like this and I click save when that in place I'll go to my label up here so I'll find another go to and I'll go to the process item that means that I will restart that item so this is how our system exception handling Works shouldn't we go test it what I will do here is that I cannot make the actual application to break but I will create a breakpoint try to click here for example number 14 also go in app and click here we will manually close it so we will mimic a system exception that could be an unstable system now you will try to run it and here let's have a success first a break point by the way that is this red dot that means that we are clicking something and now our workflow stops and it will continue once we click run here so when I click run here it will click the plus it will click the tree it will process now we're having the next item and now I want my system to break so before you click run try to close this now if our workflow works then we should go into the open app whenever I click run here so I click run here now our workflow will look for the plus button it cannot find it there there you go now we are in the open app it tried to reopens and you can see it succeeds but we want to test the system exceptions so I close it I click run again so now it will check and of course it cannot find it so it will retry it will open it up three times there you go now it it before this if window happens I'll close this I'll try again and yes I want to stress test this I want to check that if this works so now we're trying again and once this is done you can see here the loop index is 3 then the loop index will be four whenever we continue When I close here and say run and then this transaction status will be set to system exception and our workflow will stop in the main so now it looks for this calculator it cannot find it now we have stopped that means that we couldn't do it and if we go to Excel data numbers there you go we can now lock both system exception and business exceptions so we had a success then we have a system exceptions and we agreed that we would stop the workflow whenever a system except exception occurred so we didn't process these but we already saw they worked and you can click close here one thing that we can do finally that could be to just remove these breakpoints go back to main go down to excel say save document save then I also want to write the Excel data numbers back to this close Excel so I find a right to Excel worksheet and drag it in yeah so I want to write in the Excel instance what value do I want to write I want to write the Excel data numbers where do I want to write it well I want to write it in a that will be where we want to start that is the a column and since we have headers in the Excel and we're not writing them from this we could do it but since we already have I will write from row 2. I will click save here and then I will click run up here and I'll fast forward see you in the end that's it if I minimize this I go out to the Excel we have now locked everything to our Excel sheet now you should join the I love automation Discord Community we are more than 7 000 RPA developers networking and helping each other with Solutions YouTube thinks you should watch this video next
Info
Channel: Anders Jensen
Views: 6,058
Rating: undefined out of 5
Keywords: error handling in power automate desktop, exception handling in power automate desktop, power automate desktop tutorial, handle exceptions in power automate desktop, exception handling power automate desktop, error handling power automate desktop, on block error power automate desktop, try catch power automate desktop, tutorial, complete tutorial
Id: zgBBijpZbPc
Channel Id: undefined
Length: 46min 7sec (2767 seconds)
Published: Sat May 20 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.