Plugins 如何在IPlugin上下文中更新Dynamics CRM 4.0自定义属性

Plugins 如何在IPlugin上下文中更新Dynamics CRM 4.0自定义属性,plugins,dynamics-crm-4,Plugins,Dynamics Crm 4,我在插件上下文中处理默认实体(电子邮件)的自定义(扩展)属性,尽管该方法可用于创建(.Add()),但它不用于更新(也不与.Update()方法关联)。以下是实际代码: public class EmailPreCreateHandler : IPlugin { DynamicEntity dynamicEntity; if (context.InputParameters.Properties.Contains("Target") &a

我在插件上下文中处理默认实体(
电子邮件
)的自定义(扩展)属性,尽管该方法可用于创建(
.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
  • 事件管道执行阶段:预阶段

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

如果出现
新属性1
新属性2
,您可能会添加/更新
新属性3

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

如果访问
dynamicEntity[“new_property3”]
forwriteaccess,它将创建属性(如果该属性不存在)或覆盖现有值。

注册有什么意义?前/后?哪条消息?@ckeller:谢谢你的贡献-我已经用插件注册细节更新了帖子。非常感谢你的贡献-你的示例代码确实更好地表达了创建/覆盖的概念-我肯定在用你的方法重构实现。@Nano欢迎你。如果您对Dynamics CRM主题感兴趣,请查看