0
votes

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. 
1
Can you please share your plugin code ? I believe the plugin is fired but your plugin/logic is not executed due to some condition.Dot_NET Pro
@Dot_NETPro: Done. Thank you, bro.iquellis

1 Answers

1
votes

Closing an opportunity by creating an order in the UI does not trigger the win message on entity opportunity. Apparently the application layer does not use the WinOpportunityRequest internally. It simply performs an update of the related opportunity (attributes actualvalue, actualclosedate and closprobability).

Register your plugin on the update message of entity 'opportunity'.

(When the quotation is lost the application layer actually does use the LoseOpportunityRequest internally.)