我的代码在Microsoft Dynamics CRM系统中生成潜在客户。有与潜在客户相关的电话呼叫活动。电话呼叫活动中有“收件人”和“发件人”属性,可以是联系人或潜在客户。我需要我的代码将引导分配给这些属性。我实现了这个:
Entity account = new Entity("lead");
lead_id= service.Create(account);
Entity activity1 = new Entity("phonecall");
activity1["description"] = "Phone call activity";
activity1["to"]=account;
activity1.Attributes.Add("regardingobjectid", new EntityReference("lead", lead_id));
service.Create(activity1);
public static Guid createActivity(Guid lead_id, Entity sendr, Entity recvr)
{
Entity activity1 = new Entity("phonecall");
activity1["description"] = ImgURL;
var activityParty1 = new Entity("activityparty");
activityParty1["partyid"] = sendr.ToEntityReference();
activity1["from"] = new[] { activityParty1 };
var activityParty = new Entity("activityparty");
activityParty["partyid"] = recvr.ToEntityReference();
activity1["to"] = new[] { activityParty };
activity1.Attributes.Add("regardingobjectid", new EntityReference("lead", lead_id));
Guid acc_id = service.Create(activity1);
return acc_id;
}
例外:Guid acc_id = service.Create(activity1);
答案 0 :(得分:0)
活动方是PhoneCall与相关“to”字段之间的连接。创建添加活动派对。
早期约束:
activity1.To = new[]
{
new ActivityParty() {PartyId = account.ToEntityReference()}
};
后期绑定:
var activityParty = new Entity("activityparty");
activityParty["partyid"] = account.ToEntityReference();
activity1["to"] = new[] {activityParty};
答案 1 :(得分:0)
每次想要关联实体时都应引用EntityReference。此外,您与之关联的实体应该已经存在。 因此,您可以将代码重写为:
Entity account = new Entity("lead");
lead_id= service.Create(account);
Entity activity1 = new Entity("phonecall");
activity1["description"] = "Phone call activity";
activity1["to"]=**account.ToEntityReference()**;
activity1["regardingobjectid"] = **account.ToEntityReference()**;
service.Create(activity1);