【问题标题】:How to update a Dynamics CRM 4.0 custom property within an IPlugin context如何在 IPlugin 上下文中更新 Dynamics CRM 4.0 自定义属性
【发布时间】:2011-08-12 13:17:28
【问题描述】:

我正在处理插件上下文中默认实体 (email) 的自定义(扩展)属性,尽管该方法适用于创建 (.Add()),但它不适用于更新(也不是.Update() 方法关联)。这是实际代码:

public class EmailPreCreateHandler : IPlugin
{
        DynamicEntity dynamicEntity;

        if (context.InputParameters.Properties.Contains("Target")
            && context.InputParameters.Properties["Target"] is DynamicEntity)
        {
            dynamicEntity = (DynamicEntity)context.InputParameters.Properties["Target"];

            if (dynamicEntity.Name != EntityName.email.ToString()) { return; }
        }
        else { return; }

        try
        {
            if (dynamicEntity.Properties.Contains("new_property1")
                || dynamicEntity.Properties.Contains("new_property2"))
            {
                var new_property3 = new CrmBooleanProperty("new_property3", new CrmBoolean(true));
                dynamicEntity.Properties.Add(new_property3);
            }
        }
        catch (SoapException exception)
        {
            throw new InvalidPluginExecutionException(
                "An error occurred with the plug-in.", exception);
        }
    }
}

我想知道我是否应该做这样的事情来让它工作?

dynamicEntity.Properties.Remove(new_property3);
dynamicEntity.Properties.Add(new_property3);

注册详情

(大会)

  • 位置:数据库

(步骤)

  • 消息:创建
  • 主要实体:电子邮件
  • 次要实体:无
  • 过滤属性:所有属性
  • 在用户上下文中运行:调用用户
  • 执行顺序:1
  • Eventing Pipeline 执行阶段:Pre Stage

我将非常感谢任何反馈。非常感谢,

【问题讨论】:

  • 注册有什么用?前/后?哪条消息?
  • @ckeller:感谢您的贡献 - 我已经用插件注册详细信息更新了帖子。

标签: plugins dynamics-crm-4


【解决方案1】:

如果存在new_property1new_property2,您似乎会添加/更新new_property3

if (dynamicEntity.Properties.Contains("new_property1") || dynamicEntity.Properties.Contains("new_property2"))
{
  dynamicEntity["new_property3"] = new CrmBoolean(true);
}

如果您访问 dynamicEntity["new_property3"] 以进行 write 访问,它将创建该属性(如果该属性不存在)或覆盖现有值。

【讨论】:

  • 非常感谢您的贡献 - 您的示例代码确实更好地表达了创建/覆盖的概念 - 我肯定会使用您的方法重构实现。
  • @Nano 不客气。我有您对 Dynamics CRM 主题感兴趣,请查看Microsoft Dynamics CRM proposal
猜你喜欢
  • 2010-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多