首页 > 解决方案 > 如果报价成功关闭,则不会使用消息“win”触发 MS Dynamics CRM 插件

问题描述

环境是 Dynamics 365,当前版本。

我们有一个在赢得机会时触发的插件。一切都很好。但是,还有另一种方法可以结束机会,那就是通过相关报价。

如果您在相关报价中并执行“创建订单”,您也有机会关闭机会。但在这种情况下,插件不会触发消息“win”。

我假设事件在链中太深而不会触发。或者说这不是胜利事件,而是更新或某事。像那样。

有没有人有这个案子的经验?有什么意见吗?

Dot_NET Pro 问题的更新:

有一些 if 条件可以从代码中解救出来。第一个是:

    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. 

第二个 if 进入具有此代码的方法:

    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. 

标签: pluginsdynamics-crmmicrosoft-dynamics

解决方案


通过在 UI 中创建订单来关闭机会不会触发实体机会上的获胜消息。显然应用层不使用WinOpportunityRequest内部。它只是执行相关机会的更新(属性实际值、实际关闭日期和关闭概率)。

update在实体“机会”的消息上注册您的插件。

(当报价丢失时,应用层实际上确实在LoseOpportunityRequest内部使用。)


推荐阅读