Create new Phonecall \ Email Activity from existting one.
String IdG=”Guid of ur Activity”
Guid LeadId = new Guid(IdG);
CrmService service = new CrmService();
service.Url = ConfigurationManager.AppSettings["Url"];
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
//service.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["CredentialsUName"], ConfigurationManager.AppSettings["CredentialsPwd"], ConfigurationManager.AppSettings["CredentialsDomain"]);
ColumnSet cols = new ColumnSet();
cols.Attributes = new string[] { "activityid", "from", "to", "phonenumber", "directioncode", "subject", "regardingobjectid", "ownerid", "actualdurationminutes", "prioritycode", "scheduledend", "category", "subcategory" };
ConditionExpression cond1 = new ConditionExpression();
cond1.AttributeName = "activityid";
cond1.Operator = ConditionOperator.Equal;
cond1.Values = new string[] { LeadId.ToString() };
FilterExpression filter = new FilterExpression();
filter.FilterOperator = LogicalOperator.And;
filter.Conditions = new ConditionExpression[] { cond1 };
QueryExpression query = new QueryExpression();
query.EntityName = EntityName.phonecall.ToString();
query.ColumnSet = cols;
query.Criteria = filter;
BusinessEntityCollection retrived = service.RetrieveMultiple(query);
phonecall actpointer = new phonecall();
if (retrived.BusinessEntities.Length > 0)
{
for (int j = 0; j < retrived.BusinessEntities.Length; j++)
{
phonecall ld = (phonecall)retrived.BusinessEntities[j];
if (ld.subject != null)
{
actpointer.subject = ld.subject.ToString();
}
else
{
actpointer.subject = null;
}
if (ld.phonenumber != null)
{
actpointer.phonenumber = ld.phonenumber;
}
else
{
actpointer.phonenumber = null;
}
Picklist p = new Picklist();
if (ld.prioritycode.Value != null)
{
p.Value = ld.prioritycode.Value;
actpointer.prioritycode = p;
}
else
{
p.Value = 1;
actpointer.prioritycode = p;
}
if (ld.category != null)
{
actpointer.category = ld.category.ToString();
}
else
{
actpointer.category = null;
}
if (ld.subcategory != null)
{
actpointer.subcategory = ld.subcategory.ToString();
}
else
{
actpointer.subcategory = null;
}
if (ld.ownerid.Value.ToString() != null)
{
Guid ow = new Guid(ld.ownerid.Value.ToString());
actpointer.ownerid = new Owner();
actpointer.ownerid.type = EntityName.systemuser.ToString();
actpointer.ownerid.Value = ow;
activityparty party = new activityparty();
party.partyid = new Lookup();
party.partyid.type = EntityName.systemuser.ToString();
party.partyid.Value = ow;
actpointer.from = new activityparty[] { party };
}
activityparty[] act = ld.to;
if (act[0].partyid.Value.ToString() != null)
{
Guid ow1 = new Guid(act[0].partyid.Value.ToString());
activityparty party1 = new activityparty();
party1.partyid = new Lookup();
party1.partyid.type = EntityName.lead.ToString();
party1.partyid.Value = ow1;
actpointer.to = new activityparty[] { party1 };
}
if (ld.regardingobjectid.Value != null)
{
Guid ow2 = new Guid(ld.regardingobjectid.Value.ToString());
Lookup lookup = new Lookup();
lookup.Value = ow2;
lookup.type = EntityName.lead.ToString();
actpointer.regardingobjectid = lookup;
}
if (ld.directioncode.Value != null)
{
CrmBoolean dc = new CrmBoolean();
dc.Value = ld.directioncode.Value;
actpointer.directioncode = new CrmBoolean();
actpointer.directioncode.Value = Convert.ToBoolean(dc.Value.ToString());
}
else
{
string stt = "true";
CrmBoolean dc = new CrmBoolean();
dc.Value = Convert.ToBoolean(stt.ToString());
actpointer.directioncode = new CrmBoolean();
actpointer.directioncode.Value = Convert.ToBoolean(dc.Value.ToString());
}
actpointer.actualdurationminutes = new CrmNumber();
int v = Convert.ToInt32(ld.actualdurationminutes.Value.ToString());
actpointer.actualdurationminutes.Value = Convert.ToInt32(30);
DateTime testdate = new DateTime();
testdate = Convert.ToDateTime(System.DateTime.Now.Date.ToString());//Convert.ToDateTime(dt.date.ToString());
DateTime testdate1 = new DateTime();
testdate1 = Convert.ToDateTime(testdate.AddDays(1).ToString());
if (testdate1.DayOfWeek.ToString().Trim() == "Sunday")
{
testdate1 = Convert.ToDateTime(testdate1.AddDays(1).ToString());
CrmDateTime dt1 = new CrmDateTime();
dt1.Value = testdate1.ToString();
actpointer.scheduledend = new CrmDateTime();
actpointer.scheduledend.Value = dt1.Value;
Guid aid = service.Create(actpointer);
newday = testdate1.DayOfWeek.ToString().Trim() + " " + testdate1.Date.ToString();
CloseActivity(objId);
Label1.Text = "New Phone Call Activity is created on " + newday.ToString();
}
else if (testdate1.DayOfWeek.ToString().Trim() == "Saturday")
{
testdate1 = Convert.ToDateTime(testdate1.AddDays(2).ToString());
CrmDateTime dt1 = new CrmDateTime();
dt1.Value = testdate1.ToString();
actpointer.scheduledend = new CrmDateTime();
actpointer.scheduledend.Value = dt1.Value;
Guid aid = service.Create(actpointer);
newday = testdate1.DayOfWeek.ToString().Trim() + " " + testdate1.Date.ToString();
CloseActivity(objId);
Label1.Text = "New Phone Call Activity is created on " + newday.ToString();
}
else
{
CrmDateTime dt1 = new CrmDateTime();
dt1.Value = testdate1.ToString();
actpointer.scheduledend = new CrmDateTime();
actpointer.scheduledend.Value = dt1.Value;
Guid aid = service.Create(actpointer);
newday = testdate1.DayOfWeek.ToString().Trim() + " " + testdate1.Date.ToString();
CloseActivity(objId);
Label1.Text = "New Phone Call Activity is created on " + newday.ToString();
}
break;
}
}
else
{
Label1.Text = "Cannot create New PhoneCall Activity for this Activity.";
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment