CRM Dynamics获取相关帐户的联系人
本文关键字:联系人 Dynamics 获取 CRM | 更新日期: 2023-09-27 18:25:55
我正在针对CRM中的帐户创建电话呼叫活动,我需要将电话呼叫的to属性分配给检索到的帐户相关联系人,我如何做到这一点,请参阅下面的代码
public static void GetRelevantOutboundCallCenter(IOrganizationService service)
{
QueryExpression qe = new QueryExpression();
qe.EntityName = "account";
qe.ColumnSet = new ColumnSet("new_accountactionedstatus", "name", "telephone1", "primarycontactid");
qe.Criteria.AddCondition("new_deliverystatus", ConditionOperator.Equal, 279640000);
qe.Criteria.AddCondition("new_province", ConditionOperator.Equal, 100000018);
qe.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0);
EntityCollection response = service.RetrieveMultiple(qe);
var counter = 0;
foreach (Entity account in response.Entities)
{
PhoneCall phone = new PhoneCall();
ActivityParty from = new ActivityParty();
phone.OwnerId = from.PartyId = new EntityReference("systemuser", new Guid("6DEFA813-56F9-E411-80CC-00155D0B0C2D"));
ActivityParty to = new ActivityParty();
to.PartyId = account.ToEntityReference();
phone.From = new ActivityParty[] { from };
phone.DirectionCode = true;
phone.To = new ActivityParty[] { to };// I need to set the related Contact of the account here
phone.PhoneNumber = account.Attributes["telephone1"].ToString();
phone.Subject = "TEST FOR OUTBOUND";
service.Create(phone);
counter++;
if (counter == 438)
return;
}
}
这是我设置查找帐户的地方,我需要这是与检索到的帐户相关的联系人——电话。To=新ActivityParty[]{To};
如果您想将呼叫分配给账户变更线的主要联系人
to.PartyId = account.ToEntityReference();
至线路
to.PartyId = account.GetEntityAttribute<EntityReference>("primarycontactid");