The environment is Dynamics 365, current version.
We have a plugin that is being triggered when an opportunity is won. Everything is fine with that. But there is another way to close an opportunity as won and that is over a related quote.
If you are in a related quote and do "create order", you have the chance to close the Opportunity as won as well. But in this case, the plugin does not trigger on the message "win".
I assume that the event is too deep in the chain that it does not trigger. Or that it is not a win event, but an update or sth. like that.
Has anybody experience with this case? Any opinions?
Update for Dot_NET Pro's question:
There are to if-conditions that bail out from the code. First one is:
public void Execute(IServiceProvider serviceProvider)
{
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationService organizationService = serviceFactory.CreateOrganizationService(null);
if (context.MessageName.ToLower() != "win")
{
return;
}
var currentOpportunity = RetrieveCurrentOpportunity(serviceFactory, context, organizationService);
if (currentOpportunity == null)
{
return;
}
// More code comes here.
The second if goes into a method that has this code:
private Entity RetrieveCurrentOpportunity(IOrganizationServiceFactory serviceFactory, IPluginExecutionContext context, IOrganizationService organizationService)
{
Guid opportunityId = Guid.Empty;
if (context.InputParameters.Contains("OpportunityClose") && context.InputParameters["OpportunityClose"] is Entity)
{ // ... more code here.
// else-case does nothing.