• Release History
  • Documentation
  • Back to www.mscrm-addons.com
  • Release History
  • Documentation
  • Back to www.mscrm-addons.com
home/Knowledge Base/DocumentsCorePack(DCP)/Handling Document Generation Errors in Microsoft Flows

Handling Document Generation Errors in Microsoft Flows

189 views 0

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: 

An overview of our flow, depicting two steps: the initial manual trigger of the flow and the "Create document (sync)" action from DocumentsCorePack.
Figure 1: The overview of our current flow

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. 

An error occurring in the "Create document (sync)" action
Figure 2: An error occurring in the “Create document (sync)” action

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. 

Our flow, now with an additional "Send an email" action.  The "run after" setting will trigger this action if an error occurs within the "Create document (sync)" aciton.
Figure 3: Our flow, now with an additional “Send an email” action. The “run after” setting will trigger this action if an error occurs within the “Create document (sync)” aciton.

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. 

On the left, our email to be sent to a specified user.  On the right, the "Terminate" action has been added to our flow.
Figure 4: On the left, our email to be sent to a specified user. On the right, the “Terminate” action has been added to our flow.

Now, if the flow runs into an error, the user will receive an email informing them of the flow’s failure. 

An email in an inbox warning the recipient of the error in our flow.
Figure 5: The email informing us of the error in our flow

Tip: To receive detailed information about the error, you can insert the body/Return value parameter into the email from the Create document action. 

The "Create document (sync)" action's Return value placed in the email action.
Figure 6: The “Create document (sync)” action’s Return value placed in the email action.
The received email, now displaying the error details
Figure 7: The received email, now displaying the error details

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. 

The upper section of a flow.  This section focuses on generating multiple documents at once.
Figure 8a: The upper section of our flow
The lower section of a flow.  This section focuses on retrieving the results of the document job and attaches the documents to emails.
Figure 8b: The lower section of our flow

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.” 

The aforementioned flow, now wrapped in a scope block labelled "Try"
Figure 9: Our above flow, now wrapped in a scope block labelled “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. 

Configuring our "Catch" block to run after the previous block if it fails
Figure 10: Configuring our “Catch” block to run after the previous block if it fails

If an error occurs at any point, an email will be sent and the flow will be terminated. 

The email sent to the user informing them of the flow's failure
Figure 11: The email sent to the user informing them of the flow’s failure

That’s it! We appreciate your feedback! Please share your thoughts by sending an email to support@mscrm-addons.com 

Was this helpful?

Yes  No
Related Articles
  • 3 Ways DocumentsCorePack Transforms Proposal, Quote, and Contract Creation
  • DeepSign for DocumentsCorePack 
  • Generate and send a document for e-signing using DeepSign
  • How to prepare a document for DeepSign
  • Why Document Generation Is Still the Most Broken Part of Your CRM Workflow
  • How to migrate One-Click-Actions (OCAs) between environments
Latest Articles
  • How to Eliminate Excess Storage Costs in Microsoft Dynamics 365 Without Losing Access to Emails and Attachments
  • 3 Ways DocumentsCorePack Transforms Proposal, Quote, and Contract Creation
  • DeepSign for DocumentsCorePack 
  • Generate and send a document for e-signing using DeepSign
  • How to prepare a document for DeepSign
Popular Articles
  • DocumentsCorePack Template Designer – Getting Started
  • Step-by-Step: How to configure a One-Click-Action
  • Application Access for Dynamics 365
  • How to find your environment’s unique name in Microsoft Dynamics 365
  • How licenses are counted
Top Rated Articles
  • “Undefined”-labels in Chrome and Edge 114 and higher
  • Important information for Dynamics 365 online customers using DocumentsCorePack and/or AttachmentExtractor
  • How to activate the DocumentsCorePack Connector for PowerApps & Microsoft Flow
  • How licenses are counted
  • How to insert Condition Fields in DocumentsCorePack Templates designer
Categories
  • *News and General Infos* 64
  • Webinars 45
  • Template Designer(DCP 196
  • DocumentsCorePack(DCP 257
  • TelephoneIntegration (TI 65
  • AttachmentExtractor (AE 74
  • PowerSearch (PS 50
  • ActivityTools (AT 61
  • SmartBar (SB 54
  • GroupCalendar (GC 47
Our Vision

“We see it as our purpose to provide products that simplify and speed up our customers’ Microsoft Dynamics 365 experience.”

Knowledgebase
LogIn
mscrm-addons.com
  • Products
  • Online Shop
  • Downloads
  • My Account
About Us
  • About Us
  • Case Studies
  • Newsletter
  • Partner Program
  • Contact
Support
  • Support
  • Terms & Conditions
  • Documentation
  • Webinars
  • Legal Documents
  • Impressum
  • © 2022 www.mscrm-addons.com. All Rights Reserved.