Skip to main content

Abort event through plugins

Suppose you are writing a pre -event plugin in which you compare to 
old and new values and on certain condition would like to cancel the Save or 
Update and stop the execution, it was simple in CRM 3 with an Abort() method
while in CRM 4, you have to manually raise and throw a 
Invalid-Plugin-Exception, while this gives a dirty error message on your MSCRM screen,
you can make it better by entering you own Message explaining why the record could
not be saved:

throw new InvalidPluginExecutionException("Execution has been stopped due to this reason");

Comments

OuSs said…
Thank you for this post,
I wonder if there are any way to do the same thing but without writing the entry caused by this in eventlog?

Thank you
Allo said…
What CRM does not seem to recognize is that sometimes there's the need for a Pre-stage plugin that would execute pretty much as an INSTEAD OF UPDATE/CREATE/DELETE trigger would in MS SQL. Say, a modification to a given field in certain conditions might have to be "cancelled" and instead treated as INSERT of another record/object. Why is there no simple way of setting something like Context.Abort = true ?
- Just treat the operation as if it had already completed successfully, and let the plug-in take care of the rest. Design flaws like this fly in the face of the claims that Dynamics CRM is a one-for-all business platform.
Hi,
Can we do the same thing without throwing an exception in CRM 4.0?
i don't want the user to see an exception.i just want to stop the action done (delete, save...).
thank you.
hero said…
Hi Charles, thanks for the post, i will see if i can get an answer to this.
ok
thank you for your prompt reply
Anything? I need this "instead-of" functionality in CRM 2011.

Popular posts from this blog

Cancel Workflow job programmatically - CRM v.4

How many times you had to created a workflow on some date like Due date which keeps changing as per client's request. While this may sound simple in business, on CRM you have a workflow that may be waiting till this date and send a reminder exactly a week before. So you need to keep calling this workflow every time the date is updated, to make the matters more complicated, all the previous jobs that had initiated due to past modification will keep running and chasing that date which is never going to occur. What you do now, manually cancel those to save system resources and stop the never ending system jobs. There is a way to do it through SDK, in my case I call this function as a custom workflow activity in the first step of the workflow which Cancels any previous jobs of this workflow.   #region Cancel My WFs             QueryExpression qe = new QueryExpression();             qe.EntityName = EntityName.asyncoperation.ToString();             ColumnSet cs = new

Microsoft reuse windows media player toolbar in Windows 7

Those who have been using Windows Media Player would have experienced one thing over time, when you click on the little up-down arrow heads on the right, you could see a thumbnail live view of the current movie you were playing. This had been since Window XP and now Microsoft have copy-pasted this code to show live preview of each taskbar window like a folder, browser session, office documents and every possible item you can open and appear in task bar.  Those of you who haven't seen Windows 7, this is how taskbar preview looks like :

Using MS CRM Calendar in your custom ASP .NET pages *** Not fully Supported Customisations ***

Hi, Have you been creating custom pages in line with MS CRM for creating , viewing and updating entity records ? Have you placed controls such as Date picker Lookup on your custom page and have tried in vein to make those look like MS CRM ? I found a way to use the same MS CRM calendar control as it appears in the application... For getting this calendar on your asp .net page, follow the steps below: 1) Create a copy of the date.js javascript file located in your-server/crmsite-folder/_static/_controls/datetime folder, give the copy some name like date_myapp.js. 2) Open the following .js files from different sub folders in side the  your-server/crmsite-folder/_static      folder :       Global.js       encodedecode.js       xmlutil.js       util.js       remotecommand.js              Copy and whole content of each file one by one and keep pasting the same to the end of your date_myapp.js file. 3) Now open any CRM entity record page, for example a new Account crea