【发布时间】:2011-03-14 15:44:48
【问题描述】:
我希望在我的创建插件中为实体“帐户”设计一些逻辑。
它的作用基本上是检查帐户名称并识别创建时重复的帐户名称。
因此,如果有一个帐户名称,例如 Barclays,并且我尝试再次创建此帐户,我将通过错误消息提醒用户该帐户之前已创建,并阻止添加此记录。
public void Execute(IServiceProvider serviceProvider)
{
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parmameters.
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName == "account")
{
bool x = true;
if (entity.Attributes.Contains("Name") != recordNamesinCRM)
{
}
else
{
throw new InvalidPluginExecutionException("You Cannot Have Duplicate Country Codes!.");
}
}
}
}
在上面的代码中,我只是使用“recordNamesinCRM”作为示例,但我确信有一个内置函数或方法可以在创建新名称时与系统中的其余部分进行比较,或者一种计算重复出现实例的方法.
【问题讨论】:
-
你最后找到解决方案了吗?我正在考虑根据联系人实体中唯一的电子邮件地址字段做类似的事情
标签: plugins duplicates dynamics-crm