Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

Preventing a save by returning from an plugin without throwing an exception

Posted on by Microsoft Employee

Greetings Dynamics gurus,

I inherited a synchronous Pre-operation server plugin on email create where I want to NOT send an email if we've already sent the user too many emails. In the case where the plugin is not supposed to send an email it needs to put a record in another entity but it is using the same service provider. In our current implementation it seems the only way to allow the save in the other entity but prevent the email from being sent is to throw an exception after logging the email attempt, this has the undesired effect of plugging up the tracelog with loads of plugin failures that are not actually failures. 

My first question is how it possible that throwing the exception after logging the attempt does not cause the entire transaction including the logging of the event to roll back? Am I not in a transaction at this point? Is a separate transaction being spawned on the same service provider for the log attempt and because its on a different entity than the entity initiating the plugin that is causing it to function?

My second question is: Is there a way to accomplish what I've described about without throwing an exception but still causing the logging to occur and the email not to get sent and without an exception using an email create plugin registration?

Thanks,

Steven

  • meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: Preventing a save by returning from an plugin without throwing an exception

    Hello,

    You can avoid the roolback by using actions. 

    I did not understand your problem...can you please screenshot your plugin's steps and your code ?  

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans