2015-05-04 58 views
0

我已经创建了通过下面的代码通过API连接更新连接实体(Dynamics Crm: creating Connection entities via API动态CRM:需要通过API

Entity connection = new Entity("connection"); 
connection["record1id"] = new EntityReference("contact", someContactId); 
connection["record1objecttypecode"] = new OptionSetValue(2); 
connection["record1roleid"] = new EntityReference("connectionrole", someConnectionRoleId); 
connection["record2id"] = new EntityReference("incident", someCaseId); 
connection["record2objecttypecode"] = new OptionSetValue(122); 
connection["record2roleid"] = new EntityReference("connectionrole", someOtherConnectionRoleId); 
var newId = service.Create(connection); 

问:我需要两个记录之间的更新连接作用

回答

0

如果我正确地理解了这个问题,你只需要沿着同样的道路前进,使用从Create得到的Id来引用记录:

// Your code 
Entity connection = new Entity("connection"); 
connection["record1id"] = new EntityReference("contact", someContactId); 
connection["record1objecttypecode"] = new OptionSetValue(2); 
connection["record1roleid"] = new EntityReference("connectionrole", someConnectionRoleId); 
connection["record2id"] = new EntityReference("incident", someCaseId); 
connection["record2objecttypecode"] = new OptionSetValue(122); 
connection["record2roleid"] = new EntityReference("connectionrole", someOtherConnectionRoleId); 
var newId = service.Create(connection); 

// And then ... 

connection = new Entity("connection"); // start from scratch 
connection["connectionid"] = newId; // needed for the CRM to know what to update 
connection["record1roleid"] = new EntityReference("connectionrole", yetAnotherConnectionRoleId); 
connection["record2roleid"] = new EntityReference("connectionrole", yetAnotherAnotherConnectionRoleId); 

service.Update(connection);