Answered by:
Plugin on Create. How to CANCEL SAVE

Question
-
Hi,
I have a plugin which runs on the Create of a record. In a particular situation, I want to prevent the record from saving. How can I do this?
My plugin runs on the Pre Stage.
(extra info: with this code, I get information from the entity:)
entity = (DynamicEntity)context.InputParameters.Properties["Target"];
Regards, Leonard
Thursday, January 20, 2011 3:43 PM
Answers
-
Hello, Leonard.
The only way to prevent the save is to throw exception like:
throw new Exception("Bla-Bla-Bla - the reason why the record can't be saved");
Microsoft CRM Freelancer
My blog (english)
Мой блог (русскоязычный)- Proposed as answer by Daniel Cai - KingswaySoftMVP Thursday, January 20, 2011 5:29 PM
- Marked as answer by Leonard_Str Monday, January 24, 2011 8:36 PM
Thursday, January 20, 2011 4:39 PMModerator -
It is recommended to throw an exception of type InvalidPluginExecutionException :)
The message used in the exception constructor will be displayed to the user (when the create is initiated from the CRM GUI).
/Jonas
- Proposed as answer by Jonas RappMVP Thursday, January 20, 2011 9:42 PM
- Marked as answer by Leonard_Str Monday, January 24, 2011 8:36 PM
Thursday, January 20, 2011 6:09 PM -
I agree with Jonas, InvalidPluginExecutionException is recommended.
Daniel Cai | http://danielcai.blogspot.com- Proposed as answer by DavidBerryMVP, Moderator Thursday, January 20, 2011 10:35 PM
- Marked as answer by Leonard_Str Monday, January 24, 2011 8:36 PM
- Unmarked as answer by Leonard_Str Monday, January 24, 2011 8:36 PM
- Marked as answer by Leonard_Str Monday, January 24, 2011 8:36 PM
Thursday, January 20, 2011 8:08 PM
All replies
-
Hello, Leonard.
The only way to prevent the save is to throw exception like:
throw new Exception("Bla-Bla-Bla - the reason why the record can't be saved");
Microsoft CRM Freelancer
My blog (english)
Мой блог (русскоязычный)- Proposed as answer by Daniel Cai - KingswaySoftMVP Thursday, January 20, 2011 5:29 PM
- Marked as answer by Leonard_Str Monday, January 24, 2011 8:36 PM
Thursday, January 20, 2011 4:39 PMModerator -
It is recommended to throw an exception of type InvalidPluginExecutionException :)
The message used in the exception constructor will be displayed to the user (when the create is initiated from the CRM GUI).
/Jonas
- Proposed as answer by Jonas RappMVP Thursday, January 20, 2011 9:42 PM
- Marked as answer by Leonard_Str Monday, January 24, 2011 8:36 PM
Thursday, January 20, 2011 6:09 PM -
I agree with Jonas, InvalidPluginExecutionException is recommended.
Daniel Cai | http://danielcai.blogspot.com- Proposed as answer by DavidBerryMVP, Moderator Thursday, January 20, 2011 10:35 PM
- Marked as answer by Leonard_Str Monday, January 24, 2011 8:36 PM
- Unmarked as answer by Leonard_Str Monday, January 24, 2011 8:36 PM
- Marked as answer by Leonard_Str Monday, January 24, 2011 8:36 PM
Thursday, January 20, 2011 8:08 PM