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

蹲街弑〆低调 提交于 2019-12-10 23:25:56

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/17041764/is-it-possible-to-stop-plugin-execution-in-ms-crm-2011-silently

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!