我有一个场景,我需要从CRM获取一个帐户列表,然后针对这些帐户创建电话呼叫活动,同时在四个不同的用户之间分配/拆分它们,请到目前为止查看我的代码并请指导我这种情况的解决方案。
public static void CreatePhoneCallActivitesForRelatedAccount(IOrganizationService service)
{
QueryExpression qe = new QueryExpression();
qe.EntityName = "account";
qe.ColumnSet = new ColumnSet("new_accountactionedstatus");
qe.Criteria.AddCondition("new_deliverystatus", ConditionOperator.Equal, 279640000);
qe.Criteria.AddCondition("new_province", ConditionOperator.Equal, 100000018);
qe.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0);
//qe.Criteria.AddCondition("ownerid", ConditionOperator.In, "6DEFA813-56F9-E411-80CC-00155D0B0C2D", "CBDD653B-57F9-E411-80CC-00155D0B0C2D", "6CE879FD-56F9-E411-80CC-00155D0B0C2D");
EntityCollection response = service.RetrieveMultiple(qe);
foreach (Entity account in response.Entities)
{
PhoneCall phonecall = new PhoneCall
{
// ToDo: How can I add a phone call activity and assign it to the above created Accounts, also to splitting them amongst 4 users in the system
};
}
}
答案 0 :(得分:1)
您可以使用以下代码:
Guid[] users = new Guid[] { <id1>, <id2>, <id3>, <id4>};
var counter = 0;
foreach (Entity account in response.Entities)
{
PhoneCall phone = new PhoneCall();
ActivityParty _from = new ActivityParty();
phone.OwnerId =
_from.PartyId = new EntityReference("systemuser", users[counter % 4]);
ActivityParty _to = new ActivityParty();
_to.PartyId = account.ToEntityReference();
phone.From = new ActivityParty[] { _from };
phone.DirectionCode = true;
phone.Subject = "phone call trial";
phone.To = new ActivityParty[] { _to };
service.Create(phone);
counter++;
}
好奇 - 您是否尝试使用搜索引擎搜索答案?我在第一页找到了答案 - https://www.google.com.ua/?gfe_rd=cr&ei=7I1hVvX4PI2u8we4v6iQAw#q=Microsoft+CRM+2011+Create+PhoneCall+C%23