Monday, June 18, 2012 7:02 PM
I am writing a plug-in that needs to fire when a record deletion is attempted and a IsPrimary (Boolean) field on the record is has a true value, I need to stop the delete from happening and pop a messge informing the user: "Cannot delete Primary Record."
This involves two things that I have not done in a plug-in before: (1) killing the transaction, and (2) Displaying a user message.
I can't find any examples of either of these actions for a plug-in. I know to kill the tranaction I will need to handle a pre-operation message (pre-validation or pre-operation?) but I'm not sure waht action to take to make sure the tranaction is killed. On the message, since we are using CRM Online, I assume there would have to be some special way of handling this since it is a server-side event that is being handled.
Any help and/or references to examples implementing these actions would be appreciated.
Monday, June 18, 2012 7:51 PM
You can stop the execution and displaying an error to the user by simply throwing an exception from your plugin as follows
throw new ApplicationException("Cannot delete Primary Record.");
- Marked As Answer by Andrii ButenkoMVP, Moderator Monday, June 18, 2012 8:42 PM
Monday, June 18, 2012 9:17 PM
Thanks Damian. This should work.
Out curiosity, is there a way to display messages from within a plug-in that may be unrelated to an exception condition?
Monday, June 18, 2012 11:10 PM
As of the latest CRM 2011 rollup updates, the only way to display a message from a plugin to the CRM website is by throwing Exception.
This is one area that is a bit lacking in CRM and I'm sure Microsoft will look into extending this further in the future.
Hope this helps.
Dimaz Pramudya | CSG (Melbourne) | http://www.xrmbits.com | email@example.com If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"
- Proposed As Answer by Dimaz Pramudya (www.xrmbits.com) Monday, June 18, 2012 11:11 PM
Tuesday, June 19, 2012 12:28 AMNot what I wanted to hear, but appreciate receiving the info. from one who knows. Thanks much.