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

发布于 2024-11-29 01:26:52 字数 1582 浏览 0 评论 0原文

我正在插件上下文中处理默认实体(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
  • 事件管道执行阶段:前期

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

I'm dealing with a custom (extended) property of a default Entity (email) within a plug-in context and despite the approach works for creation (.Add()) it does not for updates (nor is an .Update() method associated). Here´s the actual code:

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);
        }
    }
}

I was wondering if I should do something like this to make it work?

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

Registration details

(Assembly)

  • Location: Database

(Step)

  • Message: Create
  • Primary Entity: email
  • Secondary Entity: none
  • Filtering Attributes: All Attributes
  • Run in User's Context: Calling User
  • Execution Order: 1
  • Eventing Pipeline Stage of Execution: Pre Stage

I will really appreciate any feedback. Thanks much in advance,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷…雨湿花 2024-12-06 01:26:52

如果存在 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"]进行写入访问,它将创建该属性(如果该属性不存在)或覆盖现有值。

It looks like you would add/update new_property3 if either new_property1 or new_property2 are present.

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

If you access dynamicEntity["new_property3"] for write access it will either create the property, if it does not exist or overwrite the existing value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文