Asked by:
MS CRM 2011: Depth of Plugin post Workflow execution.

Question
-
Hi,
I want Opportunity to be lost as Cancelled via a OOB Workflow executed on some condition on Opportunity page, but not manually through clicking 'Close As Lost' ribbon button and selecting Cancelled.
I have written a Plugin which checks for Depth = 1 on SetStateDynamicEntity message name of Opportunity. If found, thrown an Exception to stop user.
Worked fine when manually clicked on ribbon button for losing Opportunity.
But I also found the same exception on OOB Workflow execution on Opportunity.
What can be done now to resolve it.
Thanks,
Arun
Monday, March 10, 2014 6:48 AM
All replies
-
Create a hidden two options flag.
In the plugin, check the value of flag and throws error only when it's false.
In OOB workflow execution, before setting the state of an Opportunity, update the flag to true. Then, the plugin won't throw an error when the workflow execute the state change.
Simpler and easier solution would be hiding the "Mark as Lost" ribbon button using Visual Ribbon Editor since you're not going to use it anyway.
Monday, March 10, 2014 10:49 AM -
This solution looks simpler and easier. But can't we have a solution without any schema changes (adding new hidden field and updating it).
Thanks,
Arun
Monday, March 10, 2014 11:18 AM -
As I mentioned in the previous post,
Simpler and easier solution would be hiding the "Mark as Lost" ribbon button using Visual Ribbon Editor since you're not going to use it anyway.
Or do you have any use of that button?
Monday, March 10, 2014 2:56 PM -
Hi,
I require 'Mark as Lost' ribbon button every time available to the user, but to be lost for specific Status Reasons of Lost Opportunity.
I mean, it can be manually lost with some specific Status Reason only.
For e.g. if there are 3 Status Reasons under Lost Opportunity, user can manually lose it with only 2 of 3 Status Reasons.
3rd one is for automatic lost process. User can not use this 3rd Status Reason manually with the ribbon button.
Regards,
Arun
Monday, March 24, 2014 6:13 AM -
For that case, check the value of IPluginExecutionContext.Mode in your plugin code other than the checking of Depth.
If the value is 0, it's synchronous and you throw an Exception to stop user/
If the value is 1, it is executing asynchronously and update is triggered by workflow (or async plugin if there any)
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); if (context.Mode == 0) { // throw new InvalidPluginException(""); }
Monday, March 24, 2014 7:55 AM