shytikov
shytikov

Reputation: 9538

Is it possible to stop plugin execution in MS CRM 2011 silently?

Is it possible to stop execution of MS CRM plugins without firing exception?

I want to forbid user action and thus created plugin listing Pre event step. My plan it to cancel all further actions after that Pre step.

How could I achieve this? Without showing error message, of course.

Upvotes: 3

Views: 4449

Answers (2)

Daryl
Daryl

Reputation: 18895

If your goal is to stop the execution of all plugins that you own, you could create a HaltPlugin entity that contains a single attribute, RequestId. Then (presumably in your base plugin class) before performing any plugin execution, check to see of the Context.RequestId is in the HaltPluginEntity table, if it is, return without doing anything, else, continue as normal.

This would give you the added benefit of not showing any error to the user, since the plugins technically complete successfully, even though no work is done.

Edit

As MarioZG mentioned in the comments, it would make more sense to use shared variables if you're only concerned about plugins (I'm not sure if they work for async plugins). If you're concerned about plugins and workflows though, this approach won't work, and you'll need to create some sort of HaltPlugin entity.

Upvotes: 1

Guido Preite
Guido Preite

Reputation: 15128

Unfortunately the only way to stop execution and rollback the changes inside a plugin is to throw an exception (InvalidPluginExecutionException)

If the plugin is registered as synchronous the exception will always show the error message and is not possible to hide it.

If the plugin is registered as asynchronous the exception is written to the AsyncOperation entity

For more information:

MSDN - Handle Exceptions in Plug-Ins

Upvotes: 6

Related Questions