您好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);
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,我总是收到错误消息
"实体ID必须与属性包中设置的值相同".
如果我遗漏了这条线
Entity.Id = Guid.NewGuid();
Run Code Online (Sandbox Code Playgroud)
然后我收到了错误
"无法插入重复的密钥."
我还尝试了各种其他方法来构建一个新的Guid,包括
byte [] bytes = new byte[16];
random.NextBytes(bytes);
entity.Id = new Guid(bytes);
Run Code Online (Sandbox Code Playgroud)
要么
entity.Id = Guid.Empty;
Run Code Online (Sandbox Code Playgroud)
结果也是
"实体ID必须与属性包中设置的值相同".
另一方面,我有一个桌面应用程序,我借助本文https://msdn.microsoft.com/en-us/library/jj602970.aspx连接到我的Microsoft CRM 2016 Office 365系统并可以复制记录行.
任何帮助是极大的赞赏.