Handling exceptions in Power Automate Desktop

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello my name is smartposttech and in this video i will make a deep dive around catching exceptions in power to make desktop with the latest version that was just released a week ago that is uh the version number is 2.1 2.1.43 point some other numbers we actually have now three levels how we can catch errors the first level is on almost every single action level for every for almost every single action you can define how power to my desktop should um should act if there is any kind of an error on that specific action so you can define if there should be a general error handling for this kind of action or if there should be a specific error handling for each type of an exception that can occur on this action to be configured and then for each of those of those error handlings you can as well configure if power automate desktop should actually continue its execution so if the flow should continue or if it should throw an exception and terminate the execution the second error handling level that was just announced or that was just uh introduced with that version of department desktop is a so-called exception block you can create a block where you put a set of actions between and then if there is any error on any of the actions in between that block and and beginning or an end of the block then the whole block throws an exception so you can compare it to like a scope in power automate in the tri-catch pattern and then you can actually configure how the power to my desktop should catch and handle that kind of exceptions that can occur within any of the actions inside that exception block now there is one important thing that you have to keep in mind is that if you define exception handling on a single action level and then you put that action into exception block then power to my desktop will actually execute both the error handling definitions so first it will follow the instructions on how to handle the exception on that specific action and then if you configure um exception handling on that action to continue the execution so that this action will actually not throw any kind of an exception then the exception block is not going to execute its own instruction for error handling however if you do configure error handling on an action level that in the end after fulfilling all the required all the rules we'll also try an exception then also the exception block is going to catch an exception and will follow its own instructions for handling that kind of an error so just keep in mind that having um exceptions the exceptions handling defined on two levels will actually uh make the power to my desktop to execute both the instructions i will show you that just in a moment so you'll get a better picture but understanding of what i mean and then the third level is obviously on the power ultimate level so because the only way to trigger the power to make desktop flows is by putting uh an action inside the power ultimate flow therefore if the power automate desktop flow fails if it throws an exception then also the action inside power automate is going to end its execution with an error and then you can actually use either the try catch pattern so that it will just try that it catches that exception or you can use the parallel block with uh run after configuration to run differently depending on whether the action ends up successfully or whether it ends up with a failure all right so now let me show you how we can use all these goodies around our exception handling one also important thing around this video is that the exception handling and this assurance is certainty that flow or i mean the flow both in power automate and the power to my desktop are not just going to fail without communicating this to anyone it's a very high requirement by most of the enterprises by most of the commercial customers because they do want to have this assurance that if their flow if their flows either rpa or the regula flows in power automate are failing then they're expecting something is going to happen so like either a group of admins is going to be notified or maybe a group of business user is going to be notified somehow or that there is going to be some kind of logging then done so this information around the failure reason is going to be safe somewhere in the end what is needed what is required is that in case of any kind of a failure or in case of any kind of an error both the power to my desktop so the rpa and the power automate flows need to have some kind of a logic that helps them to either end up with information sent to kind of a group decision group that will then follow the further steps or that you'll somehow try to repeat its actions or maybe just terminate the execution with information stored for example in azure insights that is pretty up to you however what i will going to show you what i'm about to show you right now is how you can actually configure this error handling in power ultimate desktop so that your rpa flows if they fail they won't just end up without any kind of sign to anyone and that you will discover days after that oh actually my flow failed and i didn't know that and now business is waiting for data for example in sap for days and it's not there because well actually the rpa didn't finish its execution all right so first first level is on the action level once you navigate to almost any kind of an action almost any kind of because there are actions that do not have the error handling because they just cannot throw an exception as they are not doing anything wrong for example assigning a variable however most of the actions that do work with the user interface of the application that do uh that does any kind of operations on the desktop level or web level they do have their exception configurations so for example this is the power automate desktop flow that i built which is um built to actually open an excel file that is going to be stored in my onedrive for business and then in that excel file it has records contact data stored and then for each of these records it actually has to open access file and then create new records in my very old contacts database very simple flow but it can actually fail on multiple levels for example the first one the first action is configured to open an excel file which name i'm passing as a variable so let me show you now what will happen if i trigger this flow and i will immediately delete the file which name is being passed by as the variable here all right so i'll now save it i have one right here so just open a second window and now i'll import the file with all the contacts oh sorry um the file is in use so i have two files the first file is the contacts and it looks like this right so it has two rows with the data now for the error handling that i'll just show you i have a second file which is named the book backup which has sorry quite different values right so right now i'm going to use the first ones of the contacts i need to close it because this way i just cannot use it and now i'm going to run the flow so the flow is now run the file was already saved to my onedrive so therefore i need to remove it and now let's see and wait what is going to happen or basically the flow should start its execution and then it should fail so let's give it a while give it a moment right so as you can see after a minute a flow failed and now the reason why it failed is actually the fact that it cannot find that excel file so now let me navigate back to my power ultimate and i'll now do here the error handling so you remember this excel file that actually had the records it had my name within and right now because it failed i will use this book backup xlsx as a kind of an excel sheet that i'm going to use if my access fails i mean if that original file is not present i mean it's it's not the very best maybe error handlings that if the original file doesn't exist let's take some fake one but it's just for the purpose to show you how you can actually configure error handling on the single action level so right now i'm going to the launch axle action and i said in most of the actions you will find this small shield at the bottom with the information with the label on error this is where you can find all the configuration that you can set for that specific action to define the instructions how power to my desktop should behave if that action draws an error so let me just click it and right here you can actually see that for all the actions so first what you can do is that you can set that this action should retry its execution so even if it fails let it retry it another time if it fails the second time well we can't do anything else no it's not true you can do much more so first you can define new rules you can define to set variables you can define to run subflows and you can actually do multiple of them so you can run multiple multiple subflows you can define multiple variables for example a variable with the information what was the error reason that you will use as the output variable and then return it department the power automated uh flow it's up to you and the next thing you can do is you can continue the flow run so that this action will actually not throw an exception or you can throw an exception so that the error is going to be then sent onto the power automate level and the flow the rpa flow is going to terminate if you decide to continue the flow then you can as well define if it should go to the next action or maybe reproduction or maybe go to the label in power to make desktop you as well can put multiple labels within your flow logic and these labels can be used as a go-to definition so we can just define where the flow should go to um the point is that if you decide to continue the flow this action is not showing an execution however these definition as it shows is for all kind of errors so no matter why this action failed this error handling is going to be executed however if you go to advanced then for each type of an action where the error handling is present you can define how it should actually behave if the action failed for very specific reasons for example if it fails to launch the excel what should it do maybe it should um launch an application um what it should do if it fails to open this extra document so that is in our case what should it do and you can define again the same rules or the same approach as you can do for this general error handling so as well you can define multiple variables you can define multiple multiple subflows and then again define whether it should continue or throw an exception one is one point is important if you define those advanced specific error handling for specific errors or reasons then the power to make desktop will first execute this instruction or will try to but for example if you define how it should behave if it cannot open the excel file but it but it fails because it cannot open the excel application then it will then execute the general action or if you do not define this general error handling for this action it will simply throw an error because it has no error handling configured i hope it is clear and understandable for me it's really logical so um i will now define how it should actually behave not here so clear this general approach but i'll define how it should behave if it fails to open the excel document so right now i'm going to define this var file name to be uh to have the value um book backup xlsx so instead of opening the file or the excel sheet that it should open um from the power automate so to send as the variable it will try to open this all always present always existing backup file and then what i want to do is i want to continue the flow but i don't want to go to the next action i want to repeat this action so that it will now try to repeat this action however with the file name set now to book backup xlsx all right so now once i have this saved you'll notice that there is a small shield present here so now i need to save it that's very important so the flows in power to my desktop are not automatically being saved so all the changes you do here are not going to be reflected by the rpa once once you try to run them from power automate unless you save so only the saved version is published to the cloud and is being used by the power to main desktop uh in the execution from the power ultimate wow a lot of names but they're really consistent okay so i have saved it okay i have the book backup closed so let me go to this flow that failed and i'll resubmit it now what i also have to do i need to again delete the contacts file that is going to be published to my onedrive immediately all right it's deleted and so let's wait again and see what is going to happen right now so in just a short while you'll see that department desktop is actually opening the excel file which is this book backup right so you can see it open the book backup and now it should open access file right so this is what is happening then the database three and now simply insert all these contacts from the excel file that were defined in this book backup so yes the bruce wayne and right after clark kent there is some mismatch with the email and the category but doesn't matter so now the flow has executed its uh its logic successfully now let's imagine a quite different scenario right now so in my flow or it's going to i mean what it's doing once after it opens the access application is it's hitting the icon open so the one here and then and then is clicking on the button sorry on the list item database three so actually this one now let me show you um so maybe maybe not let me show you but if this um record here this item here is not present then the flow will obviously fail so let me show you and i'll remove it from list okay so it's done now just close the xs application and i'll just run this flow right from here so we'll see that it's going to fail on trying to click this database here so now i'm just i'm launching this this rpa locally so not via the um from this data gateway just via uh just as my local machine is my local instance so now it's trying to open the book backup xls6 right all fine it's all working now it's opening the access application now it's going to hit the open and now it's looking for this database tree which isn't present so obviously let me give it just a moment a minute oh sorry a second more okay i think it failed already so now once i open the the rpa here it reads that well it actually failed on that level on that list item database three so um for this purpose i want to show you how we can actually encapsulate a set of actions within the exception block so you need to type in the block and then you will find an action that is called on block error so first you need to define the beginning of the block error and then from its name and then you can as well define the rules which we are somehow not familiar from defining them on the specific action level so here again we can define the variables we can define to run subflows and again we can do multiple of them and then anything here defined any instruction defined here for catching errors for that block is going to be executed now what i want to do i'll just save it for now without the further configuration and i'll put these two actions inside the block so without any configuration this block is just going to throw an exception if there is any error in any action inside that block i have created a subflow that is called the open database and this slab flow what it does is simply hitting the button bros so here the browse and then in the browse it is just navigating to the documents and then it is opening the file that is the database 3 the access file so if the file is not present here is if it is not one of the recently opened files this subflow is simply going to manually open it from the list of all databases stored on this machine so this is what it does it then clicks the documents item in the tree level in the three uh the explorer tree then it types in database three so the name of the of the database that it needs to open and then it simply hits the button open in the module window so what i'm going to do right now is i'm simply going to use this subflow as the one that has to be run in that exception block so i'll run the subflow opendb and i'll simply say yes continue to flow so continue but this time not to the next action i want you to simply navigate to the end of the block so i presume that if there is any action happening on each of these uh of the actions present inside the block that it means the flow is not able to actually open uh the database as the one from the recent files and therefore it simply needs to go this work around to manufacture to mimic the manual opening of a database file that is stored somewhere on the on the machine so therefore i want to go to the end of the block so now let me show you how this flow is going to act right now uh yeah i just made a an error here so this action the button new contact should be outside but these two should be inside all right so um yeah so this action should be outside this to be should be inside and now let me show you how this flow now is going to work so now i will again run it locally on my local machine so you will see how it's going to work so there is again no azure uh gateway service involved there is no one from system gateway being called everything is happening locally so i can like test run how it works so now it's trying to open excel file because the one that is defined as a default value doesn't exist either then once this is done it will open the access application and then it will hit to open i mean the hit icon open but it cannot defile in the recently used file so you cannot find through the database tree so right now it will follow the subflow logic so it will browse for the file following the instructions so yes it is opening database so right now it simply open the file uh using this workaround approach and then it will simply continue the execution if anything went fine in the first place so like if this file was still present as one of the recent files right there is information that those records could be possible duplicates we need to live with that that's fine um all right so you saw that even though that the flow actually failed um on opening the on clicking the ui element so i'm trying to click this list item database tree in the end it was still able to follow the instructions defined in the subflow and so the block actually worked fine all right so then the last thing i want to show you is actually how we can catch these errors on the power ultimate level um so i will simply remove this logic from the first action so i'll just go to the advanced and i'll clear the all and so if there is any action happening inside this block i'll just turn off this as well if there's any action happening in this action it will simply throw the error and so once it throws the error this flow is simply terminating and it's sending the error reason what i can do as well let me just show you i can define here one output variable is going to be called all right and now what i can do here is i can simply define okay i didn't save the action configuration so i need to go here again and click this again and what i can do here is i can set the variable again this var error variable to all right so this is going to be the message sent back to the my power automate and i will simply throw this error and that's it so now i know that if there is any kind of an error in this action it will simply fail and it will not execute the the workflow uh any longer so now i need to save it again and then i will do here a small enhance so what i will do i will try to create the try catch pattern so to do that i need to actually use scopes now scope is this magical action that behaves like an exception blocks like if there is any error that happens inside a scope it will be reflected on the scope level so what i can do now is to add another scope it will be called let's rename it catch so this one let's rename to try and then catch is going to be executed so you need to go into configure right after if the try block times out is skipped is failed but not if it completes successfully and then inside the catch i will simply add the compose action and um and then there is this error you can see there's one of the actions returned already one of the variables dynamic variables returned by my power automate desktop flow that i just defined seconds ago but i saved it so it's immediately present it's really awesome so i'll just output it and the last thing i'm going to do is to use the terminate because i still want to have information that this flow failed now with catch action this is going to happen the same as if you would define the instruction in catch in exception block in part of my desktop to continue the run that there is no error reflected in the flows run history right so i need to fail it and then the message can be as well the one returned here so let me save it and now i'll test it again by providing the same file that i will again immediately remove but because i don't have now the configuration that is going to use a backup file if the original one doesn't exist therefore the flow should fail okay now run it and now i simply need to remove it in my onedrive you don't see it but i do i have it opened in a separate window so right now it's being executed and again in some time around a minute we should see that the try block fails however the catch block catches that failure and displays the error reason and also ends up with a terminated action that status is fail so the let's say overall failure status is going to be reflected as well in the flows from history all right so it failed you can see that the action here failed now this one the catch block was executed um possibly something went wrong with this assignment of the variable let me just check it what can we find here there is nothing inside but in the end well it failed so we can read the error details here so that it is unable to open the file actually and so we can use these error details as well as the definition to be locked for example in azure insights in azure um app insights and so this way we can monitor or well actually you can just send us an email or do whatever else also in power out to my desktop if anything fails if anything fails either in the exception block or just for a single action you can create yourself another subflow that will for example contain the uh the mail action so that it will send an email um to well id help desk or other decision group of um employees so that it will notify uh dissidents as well that there has been some kind of an issue with information or you can as well do if it fails you can do like error handling subflow and here the first action that you could perform let me just create it is what what would we need very much to have a really a lot of information what it fails obviously to do a screenshot so we can use a screen sorry ah just go away so we can do the screenshot right then well you should save it to a file we need to define the file i'll just not follow all the instructions here very carefully but what what i mean is that first you need to take a screenshot and then you can say email and use the action for example to send an email via the exchange or send the email pio outlook client or simply send an email via a defined outbox that you can configure here and then you can simply use an attachment that is the screenshot that you have created in the first in a first step so this way you can actually notify um business users or admins or i.t not only that the flow fails failed sorry but as well with the screenshot or with the screenshots that will provide much more information on what was the status of the rpa of the desktop as the flow fails so they'll have even more information for example where it was trying to click and why it failed and with that i wanted to thank you for your uh for your patience and for being with me until the end of this of this recording i hope that it will clearly help you to understand how all those exception handling methods can be configured and can be used in power to make desktop on that we have three levels right the level of the action the level of the exception block and the level of the power ultimate flow so there we can define how these rpa runs the exceptions in those rpa runs can be handled thank you very much for watching if you have any questions simply write them down in comments if you have any questions to me as well you can simply follow me on aka dot ms slash positec and find uh more contact details there write me an email find me on twitter and please subscribe to this channel because you will find a lot of more awesome information around power automatic desktop in the upcoming days once again thank you very much for watching and stay tuned bye
Info
Channel: Tomasz Poszytek
Views: 2,368
Rating: 5 out of 5
Keywords: Microsoft, Office 365, Microsoft 365, Power Platform, power automate desktop tutorial, power automate desktop app, power automate desktop ui flows, power automate desktop handling exceptions
Id: WWlyyirAqXM
Channel Id: undefined
Length: 32min 30sec (1950 seconds)
Published: Mon Nov 16 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.