Exception Handling in Power Automate and Power Automate Desktop By Ruchika Agarwal

 Exception Handling in Power Automate and Power Automate Desktop

 RPA (Robotic Process Automation)

The process of automating business operations with the help of robots to reduce human interventions is said to be RPA.


What is Power Automate?

  • Power Automate is a market leader in the RPA Tools space.
  • This software is used to automate repetitive tasks and rule-based processes.
  • It has drag-and-drop functionality.
  • Its user interface is simple to grasp and enjoyable to use.
  • Overall, using this application is a fantastic and entertaining experience.
  • Because it is from Microsoft, the customer service is excellent.

Why Power Automate?

  • Cost :- Power Automate is from Microsoft, they started giving this tool for free of cost for basic features and for advance features we have to pay very less when compared with the power automate.
  • Increase Productivity: Humans work for 10 hours a day, but robots work without rest.
  • Improved quality assurance: While working as a human, we can make mistakes, but robots will always provide 100% accurate results.
  • Better management capabilities: It is well managed, and despite being free, it contains all of the necessary features.
  • Basic Coding knowledge: A very basic understanding of coding is required.

What is Trigger? :- Is a starting action for the flow.

What is Action? :- What we expect to happen when a trigger is triggered.

Ways to create a Flow?

  1. Start from Blank
  2. Start from Template
  3. Start from a Connector

Different types of flow:-

Schedule Flow :-
  • Schedule Flow is exactly what it sounds like. 
  • The flow will run based on a set date and time. 
  • This type of flow is best when you want to set the flow to run on a specific date and time.

Automated Flow :- 
  • There are a lot of automated flow triggers, but every one of them starts with “when”. That’s because it will only run when the specified conditions are met. 
  • An Automated Flow is recommended when you want a flow to run whenever specific conditions are met, depending on which type of Automated Flow trigger you choose.

Instant Flow :-
  • The Instant Flow is perhaps the most popular and commonly used flow type. 
  • It is widely used when building Power Apps applications since most of the time it is required to complete the more complex applications. 
  • Instant Flow is perfect for Power Apps applications and whenever you want the flow to run immediately after an action, given that it is on the list of triggers available for Instant Flow.

UI Flow :-
  • This flow type is best for automating repetitive tasks in basic applications.
  • Think of UI Flows as Robotic Process Automation (RPA), or Macros if you’re a gamer. It works by basically recording your actions (Clicks, Keyboard Inputs, etc) for an application, and then plays it back to other users.
  • Note that there are two different types of UI Flow: Desktop App and Web App. 
  • Desktop apps run on Windows desktop, while Web App runs on Microsoft Edge (Chromium and Google Chrome).

Business Process Flow :- 
  • The Business Process Flow is also quite new to the flow family. 
  • However, it is also different from the other flows since it uses Microsoft Dynamic 365 to ensure data consistency throughout the whole process.

Introduction Of Exception handling

What is Exception Handling?

Exception handling is a mechanism in Power Automate Desktop that allows it to handle and recover from unexpected circumstances and issues that may arise during a flow run.

What are Exceptions? 

Exceptions are events that occur during the execution of a flow. If these exception events are not handled properly, they disrupt the expected flow of actions and cause them to fail.

Several factors could be to held responsible:
  • Incorrect Data
  • Unexpected Value 
  • Failures in software or hardware
  • Resources are unavailable

1.) Exception Handling - Power Automate 

What is Scope Control ?

  • A Scope control is an effective method of organizing or grouping actions and conditions in Power Automate flows.
  • We can also have multiple scopes for various purposes. As a result, we can divide the actions into various categorical steps or logical units. Using scopes in complex flows simply makes things easier.

For what Scope Control is used ?

  • It's also a more preferred method of handling errors in your flows. Using the Scope control, you can combine all error messages from all actions. As a result, you do not need to create individual error handlers for each of the actions. A scope can simply be used as an error management block in your flow.
  • Hide sections of the flow that you aren't working on right now.
  • Reduce the size of your workspace and clean it up.
  • And allow you to concentrate on the actions you're actively editing.

What is “Run After”?

This feature allows you to automate a specific action to occur only if another action occurs in a specific way.

How to configure “Run After”?

In Power Automate, "Run After" can be configured from one of four options:
  1. Is successful - If the action is completed successfully.
  2. Has failed -  An action can fail in any way (except timeout).
  3. Is skipped - A step was omitted. When a condition is not met, or when a previous action fails, actions are skipped.
  4. Has timed out - An action has expired. This can happen if the call to the backend times out (120 seconds) or after 30 days for long-running actions like approvals.

What is Try-Catch-Finally?

  • To handle advanced errors, the Try-Catch-Finally statement is used.
  • The try-catch-finally statement handles some or all errors that may occur in a code block.
  • Errors can be caused by coding mistakes made by the programmer, incorrect input, or other unforeseeable circumstances.

Try-Catch-Finally used for :-

  • The try statement allows you to define a block of code that will be tested for errors while it is being executed -> this will be your Power Automate Actions that describe the logic of your business process.
  • The catch statement allows you to define a block of code that will be executed if an error occurs in the try block -> this will be your Actions inside Power Automate that you want to run if some failure occurs in your business process's standard actions.
  • The finally statement allows you to run code after the try and catch statements, regardless of the outcome (if there was a fail inside the try statement or if everything was completed successfully).

Practical:-

To better understand the Exception Handling in Power Automate, I used five examples.

Example 1:- 
1.) TestExceptionHandling(ExcelFileNotPresent) 

2.) If the scope 2 fails, I want the email to be sent.

Example 2:-  
1.) TestExceptionHandling(is successful)

2.) If the Scope 2 is successful then only i want the mail to be triggered.

Example 3:-  
1.) TestExceptionHandling(Try,Catch,Finally)

2.) I wanted to run Catch if the Try was successful, and in any case, whatever the situation was, I wanted the Finally action to run.

Example 4:-  
1.) TestExceptionHandling(IsSkipped)

2.)  If it is skipped then run the flow. Skipped means that the if condition was not met in order for the flow to be executed, but you still run the flow by skipping that step. In this example, the dotted line indicates that the step has been skipped.

Example 5:-  

We are working on an approval flow in which the manager must approve the request within seven days or else it will be forwarded to the senior manager.
 
1.) TestExceptionHandling(TimeOut)

2.) We're working on an approval process that requires the manager to approve the request within seven days. Set the time here. In this case, if it is not approved within 7 days, the flow will be skipped.
P7D:- For the period of 7 days
PT1M:- For the period time of one minute.



3.) here we can configure the run after settings.

Summary:-In Power Automate for Desktop, exception handling is a mechanism that allows it to handle and recover from unexpected circumstances and issues that may arise during a flow run.

2.) Exception Handling - Power Automate Desktop

There are two types of exception handling.

  1. Action-Level  Exception Handling
  2. Block-Level   Exception Handling

Properties of Exception handling.

1.) Double-click on the specific Action to reveal the "On Error" property.

2.)  Retry action if an error occurs :- 

3.) Throw Error:- 

4.) In the build, "Continue flow run" has three properties: "Go to the next Action," "Repeat Action," and "Go to the Label."

5.) We do have the Advance property, which provides relative options based on the actions.

6.) We can configure the New Rules by using the "Set Variable" or "Run Subflow" commands.

7.) We can set up the rules here, then click "Return to Parameters" and save it.

Action-Level Exception Handling

What is Action-Level Exception Handling in automate desktop?

We can easily handle any exceptions or errors that occur at the action level by using Action-Level Exception Handling.

Eg:- To understand Action-Level Exception Handling, I used a real-time example in which I am achieving real-time Covid data, storing it in an Excel spreadsheet named CovidData.xls, and then sending an email. 

Case 1:- "Throw Error"
In this case, I'm intentionally using the incorrect Excel name and handling the exception at the action level.

1.)Go to the Launch Excel Action :- 

2.) Double-click on the Launch action Excel Action, and then use the incorrect Excel spreadsheet named Data.xls instead of CovidData.xls. and save the changes.
 
3.) Here we have set a "Throw error" property where we have set the variable name as error message and saved it.


4.) Here we go, we got the exception or error.

5.) Here is the ErrorMessage :-

6.) This blue icon is the indication that we have used the Error Handling

Case 2:- "Continue Flow Run" ----> Go to Next Action

In this Action it will skip the action and will move to the next action.

1.)  Double-click on the Launch action Excel Action, and then use the incorrect Excel spreadsheet named Data.xls instead of CovidData.xls.

 2.) Even if the excel name is wrong please go to the next action , we are setting up  "Continue Flow Run" ----> Go to Next Action.

3.)Here we go, it handled the exception, and even if the 7th step failed, it proceeded to the 8th step. 8th Step failed because that output is coming from 7th step.

Case 3:- "Continue Flow Run" ----> Repeat Action

The Repeat action will repeat the action over and over. In our case, because we have set the action Repeat action, the flow will not find the excel file on the desktop and will continue to search for an indefinite period of time.

1.) On Error ---> Continue Flow Run ----> Repeat Action


2.) See it has an infinite loop, its never ending.


Case 4:- "Continue Flow Run" ----> Go to label 

In this case even though the email ID is wrong its going to the label and performing the action.

1.) "Continue Flow Run" ----> Go to label --->Select the label

2.) As show in the screenshot it handed the exception on step 1 and it ran the flow without any interruptions.

Block-Level Exception Handling

If an error occurs throughout the flow, it can be handled using the Block-Level Exception Handling. 

Eg:- In this scenario, I'm connecting to SQL Serve, running the query, and then disconnecting.

Case 1:- New Rule ---> Set a variable
If my connection details for connecting to the SQL are incorrect, an error message stating that the connection is incorrect will be displayed throughout the flow.

1.) Go to Actions ---> Search for Flow Control ----> On Block Error

2.) Double Click on On block error ---> Give the Name to Block Error ---> Save 

3.) This is how On Block Error will be added.

4.) Set a Variable and provide the comments.

5.) Run the Flow as we have wrong connections it will through the error with Error message that we have set in the variable.


6.) Error message variable is showing the error.


Case 2:- New Rule ----> Run Sub Flow 
If my connection details for connecting to the SQL are incorrect, then the sub flow will run.

1.) Go to Add a New Rule ----> Run subflow


2.) Run subflow ---> Select the subflow name

3.) Even though the connection details are incorrect, the subflow is still running.

Case 3:- "Continue Flow Run" 

We have several options for how to proceed based on our business needs.

Conclusion of Power Automate for Desktop Exception Handling:- 

In Power Automate for desktop, exception handling is used to prevent errors when flows encounter unexpected circumstances. To handle these circumstances and ensure the flow's continuation, the exception handling behavior of each action can be activated and customized. Exception handling rules can also be assigned to entire blocks of actions.


Thank you for your time:)

Comments

Post a Comment