Plugin Pre-validation Operation to Show an Error Message as well as Log the Error

By | March 7, 2017

Introduction:

We had a business requirement, where we created a custom entity with a grid of Associated Accounts. Here, we wanted to restrict the Account while adding Accounts in the Associated View. We wanted to do this when the Account does not have the status reason ‘Approved’ by showing an error message and sending an email to the owner of the account

Issue?

As we know, to show an error message using plugin, we have to use InvalidPluginExecutionException.

However, when we use InvalidPluginExecutionException it rollbacks any additional code executed on ‘Pre-operation’ and ‘Post-operation’ irrespective of it being ‘Synchronous’ or ‘Asynchronous’.

The need over here was not just to throw an error and notify the user but also send an email/log an error in the background.

Throwing an exception in the plugin registered on “Pre-Operation” or “Post-Operation” would also prevent the additional logging of the error message that was required.

Solution:

We found an alternate way to achieve this by registering plugin on “Pre-Validation” operation.

Pre-validation operation allows processing the actions written, before throwing invalid plugin exception.

We added a new plugin step and registered it as seen in the below screenshot:

Plugin Pre-validation operation to Show an Error Message

We have also written the code mentioned below to process actions before throwing invalid plugin exception:

 

Conclusion: Code in ‘Pre-validation’ is executed outside the transaction and therefore any updates made to the database in this stage persists and can therefore be used for error logging mechanism that needs to be implemented.

QuickBooks Integration with Dynamics 365/CRM – Get the Best of Both Worlds with InoLink!

Category: Dynamics 365 Dynamics CRM 2016 Plugin Tags:

About Inogic

Inogic is one of the most renowned Microsoft ISV with a Gold competency in Microsoft Dynamics CRM ecosystem. Inogic is a hub of innovation, and cutting-edge technologies delivering innovative services and solutions like Maplytics™, one of the first geo-analytical mapping solutions to be Certified for Microsoft Dynamics (CfMD) & InoLink: QuickBooks Integration, to CRM Customers and Partners alike.

Leave a Reply