2015-05-04 59 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);