Hi Experts,
Here I have requirement that copy all Activities from one entity to another entity. In Activities we are having Email,Task,Phone call etc. We can't copy all activities in single shot.So I am using switchcase statement for copying activities. But as all knows that switch case is not preferable for developers.So is there any other way to copy activities from one entity to other.?
Its really helpful to me if anyone give idea to achieve this.
Here I mention the sample code.
var query = new QueryExpression("activitypointer");
query.Conditions.Add("reagrdingobjectid", ConditionOperator.Equal, theIdOfTheRelatedRecord);
query.ColumnSet = new ColumnSet(true);
var activities = service.RetrieveMultiple(query).Entities;
foreach (var activity in activities)
{
string activitytype = activity["activitytypecode"].ToString();
switch (activitytype)
{
case "email":
var myEmail = new Email();
myEmail["regardingobjectid"] = new EntityReference(logicalName, id);
myEmail["subject"] = activity.Attributes.Contains("subject") ? activity.Attributes["subject"] : null;
OrganizationService.Create(myEmail);
break;
case "task":
var myTask = new Entity("task");
myTask["regardingobjectid"] = new EntityReference(logicalName, id);
myTask.Attributes.Add("subject", activity.Attributes["subject"]);
OrganizationService.Create(myTask);
break;
}
}
Please suggest me better approach.
Thanks in advance.