Flows are critical to automating document generation processes. They can be triggered to run in a variety of circumstances and can be responsible for generating multiple batches of documents over an extended period of time. Naturally, it is possible, however unlikely, that the DocumentsCorePack Connector’s actions can fail, most significantly in the case of document generation failures. As a result, it becomes imperative to trace errors and retrieve information on them to prevent faulty flows from running continuously without detection.
In this article, you will learn how to outfit your DocumentsCorePack flows with error handling and how to notify a specified user when an error occurs when generating documents. Two different error handling methods will be explored.
Using “run after” to capture errors
One of the ways we can handle errors is by using the “run after” setting, a setting that will trigger an action after a previous action runs.
In a case where we have setup an on-demand flow to create and save a document to SharePoint, our flow is as follows:
The Create document (sync) action will succeed if the document is generated and saved without issue. However, if the action fails, then an error will occur.
When an error occurs, the flow status will be marked as “Failed” in the flow’s run history, but the user will not be notified of the error unless they check the flow’s history themselves. In such situations, an erroneous flow could continue to run without the user being aware, potentially leading to significant document generation failures.
To resolve this issue, we can create a new action which will “run after” the document generation step that will notify the user if it fails.
The “Run after” setting
We will add a Send an email (V2) action to our flow. On its own, the action sends an email to a specified user if the previous actions succeed; it won’t if the previous actions fail. This is not the case if we use the “run after” setting within the action.
The “run after” setting will allow an action to trigger after a previous action depending on the previous action’s outcome. The user can choose if the action should trigger after the previous one
- Succeeds
- Times out
- Is skipped, or
- Has failed
In our case, we want the ❶ Send an email action to trigger if the Create document action fails. After adding the action, we will configure its ❷ Settings so that the action will run after the ❸ Create document action ❹ has failed.
This email will notify a specified user that the flow has failed. An additional Terminate action will end the flow and mark it as failed in its run history.
Now, if the flow runs into an error, the user will receive an email informing them of the flow’s failure.
Tip: To receive detailed information about the error, you can insert the body/Return value parameter into the email from the Create document action.
Using a “try-catch” block to capture errors
Errors can also be handled using scope blocks in combination with the “run after” action.
In a separate case, we have a flow that will generate a document for each account record in our system. Each generated document will be saved and attached to an email to be sent later.
This flow uses the async version of the Create Document action, which differs from the sync version by first generating AutoMergeWorkingItems and then later retrieving the results through the Get DocumentJob result action. This approach is good for generating multiple documents at once.
This flow consists of multiple actions, meaning multiple points of potential failures. Our previous method of error capturing would be inefficient. A better approach would be to utilize Scope blocks.
Scope blocks
Scope blocks group actions into a singular, organized structure, ensuring that actions occur strictly within its boundaries. By placing our actions within a scope block, we can trigger a “run after” action if any of the grouped actions runs into an error.
For this flow, we’ll place our actions into a scope block called “Try.”
Then, we’ll create another block called “Catch,” which will trigger an email to be sent after the “Try” block if an error occurs.
If an error occurs at any point, an email will be sent and the flow will be terminated.
That’s it! We appreciate your feedback! Please share your thoughts by sending an email to support@mscrm-addons.com