【问题标题】:"entity.Attributes.Contains" method never returns true“entity.Attributes.Contains”方法永远不会返回 true
【发布时间】:2014-05-29 08:42:59
【问题描述】:

尝试在事件实体更新事件中创建 CRM 插件。

这是一个完整的插件代码

namespace MyPluginPackage.Plugins{
using System;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;

public class PreValidateCaseUpdate: Plugin
{
    public PreValidateCaseUpdate()
        : base(typeof(PreValidateCaseUpdate))
    {
        base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(10, "Update", "incident", new Action<LocalPluginContext>(ExecutePreValidateCaseUpdate)));
    }

    protected void ExecutePreValidateCaseUpdate(LocalPluginContext localContext)
    {
        if (localContext == null)
        {
            throw new ArgumentNullException("localContext");
        }

        IPluginExecutionContext context = localContext.PluginExecutionContext;
        IOrganizationService service = localContext.OrganizationService;
        if (context.InputParameters.Contains("Target") &&
        context.InputParameters["Target"] is Entity && context.Depth < 2)
        {
            Entity entity = (Entity)context.InputParameters["Target"];
            try
            {

                if (entity.Attributes.Contains("customerid"))
                {
                    //Some code. For example updates incident entity description
                    entity["description"] = "Some description";
                }

                service.Update(entity);
            }
            catch (FaultException ex)
            {
                throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
            }
        }
    }
}}

问题是 如果 (entity.Attributes.Contains("customerid")) 永远不会返回 TRUE。 “customerid”是事件实体的标准属性。非常感谢任何想法和建议。

描述了我使用的部署插件的方法 in this blog post:

【问题讨论】:

    标签: c# crm dynamics-crm-2013


    【解决方案1】:

    更新哪个字段调用插件执行?如果 customerid 未更新 - 它不会出现在 Target 中,因此您应该使用 Images。我相信我已经在其他论坛上写过了...

    【讨论】:

    • 谢谢。注册 PreImage Alias 有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-25
    • 2016-02-08
    • 2020-02-27
    相关资源
    最近更新 更多