如何向 CRM WebAPI 中的实体添加参与方列表字段?

How can I add a party list field to an entity in CRM WebAPI?

当我要创建活动响应实体时,我需要添加一个派对列表属性,此属性的键是 "campaignresponse_activity_parties" API.

这段旧代码解释了我想做什么:

Entity party1 = new Entity("activityparty");
party1["addressused"] = email;
party1["partyid"] = new EntityReference("lead", lead.Id);
EntityCollection partyList = new EntityCollection();
partyList.Entities.Add(party1);
campaignResponse["customer"] = partyList;

我在互联网上尝试了一些方法,例如 this,但没有成功,在创建活动响应时没有出现错误,但派对列表字段未添加到活动响应实体记录中。

我目前的代码是这样的:

JObject party1 = new JObject();
party1["addressused"] = email;
party1["partyid_lead@odata.bind"] = "/leads(" + lead.Id.ToString() + ")";            
JArray partyList = new JArray();
partyList.Add(party1);
campaignResponses["campaignresponse_activity_parties"] = partyList;

如果有什么我忘记做的,请告诉我。

您还必须添加 participationtypemask。我不太确定数字(11 或 4),我现在没有在我的手机上测试这个代码就回答了。

JObject party1 = new JObject();
party1["addressused"] = email;
party1["partyid_lead@odata.bind"] = "/leads(" + lead.Id.ToString() + ")";            
party1["participationtypemask"] = 11;
JArray partyList = new JArray();
partyList.Add(party1);
campaignResponses["campaignresponse_activity_parties"] = partyList;

Reference