如何在 IPlugin 上下文中更新 Dynamics CRM 4.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果存在
new_property1
或new_property2
,您似乎会添加/更新new_property3
。如果您访问
dynamicEntity["new_property3"]
进行写入访问,它将创建该属性(如果该属性不存在)或覆盖现有值。It looks like you would add/update
new_property3
if eithernew_property1
ornew_property2
are present.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.