Dynamics CRM使用C#代码合并两个联系人,从SDK中修改了示例



我一直在尝试让Dynamics CRM 2011 SDK中的Merge示例发挥作用。http://msdn.microsoft.com/en-us/library/hh547408.aspx

我修改了一点。我已经创建了两个Contacts而不是Accounts(尽管代码中的一些变量名称可能会提出其他建议。例如_account1Id实际上是contact1的GUID。)

第一个联系人记录中填写了姓名和电话字段。第二个联系人记录中填写了姓名、姓氏和电子邮件字段。

发生合并的部分如下。原始代码可以从顶部的链接中看到。

当我运行带有以下修改的示例时,电子邮件地址不会合并到新的联系人记录中。我得到的是一个合并的Contact,其中包含一条记录中的值,添加了地址数据,但没有电子邮件。我认为这应该用第二条记录中的非空字段填充主记录的空字段。

作为一名刚接触过MsDynamicsCRM的人,经过大量的谷歌搜索和调试,我无法理解原因。如果有人能给我一些关于问题的反馈,我会很高兴。

提前谢谢。

_serviceProxy.EnableProxyTypes();
CreateRequiredRecords(); // created two contacts with same name, surname. first record has telephone1 filled, second record has emailaddress filled.
EntityReference target = new EntityReference();
target.Id = _account1Id;
target.LogicalName = Contact.EntityLogicalName;
MergeRequest merge = new MergeRequest();
merge.SubordinateId = _account2Id;
merge.Target = target;
merge.PerformParentingChecks = false;
Contact updateContent = new Contact();
updateContent.Address1_Line1 = "test";
merge.UpdateContent = updateContent;
MergeResponse merged = (MergeResponse)_serviceProxy.Execute(merge);
Contact mergeeAccount =
(Contact)_serviceProxy.Retrieve(Contact.EntityLogicalName,
_account2Id, new ColumnSet(allColumns: true));
if (mergeeAccount.Merged == true)
{
Contact mergedAccount =
(Contact)_serviceProxy.Retrieve(Contact.EntityLogicalName,
_account1Id, new ColumnSet(allColumns: true));
}

这种行为正如预期的那样-合并会将子记录从下级转移到主记录(因此可能是机会、地址等),但不会试图确定要复制的字段。原因(我想)是潜在的商业逻辑影响是无穷无尽的——你想通过电子邮件复制吗?如果所有电子邮件字段都已填写,该怎么办?自定义字段呢?还有很多其他的案例,我相信每个人都能想到。

编辑:

为了解决此问题,MergeRequest类上有一个名为UpdateContent的属性。如果更新此属性上的字段,则这些值将合并到父记录中。

你可以在你发布的链接中看到这一点:

// Create another account to hold new data to merge into the entity.
// If you use the subordinate account object, its data will be merged.
Account updateContent = new Account();
updateContent.Address1_Line1 = "test";

最新更新