【发布时间】:2016-05-17 09:43:39
【问题描述】:
您好 StackOverflow 社区,
我只是尝试从插件或自定义工作流活动中复制“联系人”实体的记录。 相关代码是
QueryExpression qe = new QueryExpression("contact")
{
ColumnSet = new ColumnSet("firstname", "lastname")
};
EntityCollection entityCollection = _organizationService.RetrieveMultiple(qe);
foreach (Entity entity in entityCollection.Entities)
{
entity.Id = Guid.NewGuid();
if (!entity.Attributes.Contains("firstname"))
{
entity.Attributes.Add("firstname", "");
}
entity["firstname"] = (entity.GetAttributeValue<string>("firstname") ?? "") + "(Copy)";
_organizationService.Create(entity);
}
不幸的是,我总是收到错误消息
"Entity Id 必须与属性包中设置的值相同"。
如果我省略了这条线
Entity.Id = Guid.NewGuid();
然后我得到错误
“无法插入重复键。”
我还尝试了各种其他方法来构建新的 Guid,包括
byte [] bytes = new byte[16];
random.NextBytes(bytes);
entity.Id = new Guid(bytes);
或
entity.Id = Guid.Empty;
导致
"Entity Id 必须与属性包中设置的值相同"。
另一方面,我有一个桌面应用程序,我在本文https://msdn.microsoft.com/en-us/library/jj602970.aspx 的帮助下连接到我的 Microsoft CRM 2016 Office 365 系统,并且可以复制记录。
非常感谢任何帮助。
【问题讨论】:
-
我认为你在microsoft dynamic crm中创建一个插件你需要注册一个插件来创建,更新等,而不需要_organizationService.Create(entity); .
标签: c# dynamics-crm dynamics-crm-2013 microsoft-dynamics