【问题标题】:Why my PostUpdateOrder Plugin executed twice CRM 2013为什么我的 PostUpdateOrder 插件在 CRM 2013 中执行了两次
【发布时间】:2017-03-09 14:41:43
【问题描述】:

在用户验证订单后,订单的状态设置为已验证并发送到另一个系统 X,问题是插件在某些情况下被触发两次甚至超过两次,导致发送此实体多次到系统 X。我试图通过使用 context.depth 来纠正它,但所有时间都等于 1。

JS方法:

Validate: function () {
        Xrm.Page.getAttribute("eoz_validated").setValue(true);
        Xrm.Page.data.entity.save();
        ABE.Order.HideVisibleField();
        Xrm.Page.ui.clearFormNotification('ProductError');
    }
}

插件执行方法:

protected void ExecutePostOrderUpdate(LocalPluginContext localContext)
    {
        if (localContext == null)
        {
            throw new ArgumentNullException("localContext");
        }
        if (localContext.PluginExecutionContext.Depth > 1)
        {
            return;
        }
        tracingService = localContext.TracingService;
        var order = (Entity)localContext.PluginExecutionContext.InputParameters["Target"];

        bool isValidated = order.GetAttributeValue<OptionSetValue>("abe_isValidated").Value : false;

        if (isValidated )
        {
            SendToSystemX(localContext.OrganizationService, order.Id);
            SendProductsToOwner(localContext.OrganizationService, order.Id);
        }

        var statecode = order.Contains("statecode") ? order.GetAttributeValue<OptionSetValue>("statecode").Value : -1;
    } 

【问题讨论】:

    标签: javascript dynamics-crm-2013


    【解决方案1】:

    如果您的插件注册为在更新"eoz_validated" 时触发并且还更新"eoz_validated",那么您可以有一个无限执行循环。

    为避免这种情况,在更新上下文实体之前,请重新实例化它:

    var updatedEntity = new Entity { LogicalName = context.LogicalName, Id = context.Id };
    

    这将删除所有本来会更新的属性,例如包含在上下文实体中的"eoz_validated"。请注意,在您的代码中,您将上下文实体存储在一个名为 order 的变量中。

    我只是在这里猜测(并且没有 50 声望来提问)。如果这发生在您的代码中,那么它可能在 SendToSystemX(IOrganizationService, Guid)SendProductsToOwner(IOrganizationService, Guid) 内。

    【讨论】:

    • 抱歉回复晚了,我删除了 SendToSystemX(IOrganizationService, Guid) 和 SendProductsToOwner(IOrganizationService, Guid)。该插件仍然执行两次。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-18
    • 1970-01-01
    • 2020-05-05
    • 1970-01-01
    • 1970-01-01
    • 2011-06-16
    相关资源
    最近更新 更多