Reputation: 555
I have a scenario where I need to get a list of accounts from CRM and then create phone-call activities against those accounts, also assign/splitting them amongst four different users, please see my code so far and please guide me to a solution for this scenario.
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
};
}
}
Upvotes: 0
Views: 142
Reputation: 5446
You can use following code:
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++;
}
Just curious - have you tried to search an answer using search engine? I found an answer on the first page - https://www.google.com.ua/?gfe_rd=cr&ei=7I1hVvX4PI2u8we4v6iQAw#q=Microsoft+CRM+2011+Create+PhoneCall+C%23
Upvotes: 1