2
votes

I need to cancel an operation of creating a new entity record from inside a CRM plugin without throwing an exception.

Is there a way of rollback the transaction inside Dynamics CRM plugin without throwing exception?

3
What is your business case for this requirement? This is basically lying to the calling code.Daryl
If there is some logic to dictate when you should and should not create the record. Are you able to evaluate the logic before creating the record in the first place?James Wood
I am trying to prevent the creation of a record based on certain conditions without throwing an exception from within the plugin. The record is being created by a workflow and the plugin triggers and should prevent the creation based on certain conditions since I CANNOT check them from within the workflow.Nick

3 Answers

2
votes

Create a Custom Action that you then call from the workflow that has a plugin in it that basically determines if the record should be created or not. If it should, it creates it, if it doesn't it just exits.

This way you don't have to throw an exception, and you can give it a good name "ConditionallyCreateFoo".

2
votes

No, you can only undo this by deleting the record within the same transaction.

0
votes

The design of triggering a workflow which in turn invoking a plugin is not so good. You could use a custom workflow and write the same logic of your Plugin into this workflow and handle the exceptions.