Saturday, February 4, 2012

CRM 2011: Reopen or reactivate a closed task / activity with SDK

Use the following line of code to Reopen the closed task in CRM 2011

// Re-open the Task to update it
SetStateRequest ssr = new SetStateRequest();
ssr.EntityMoniker = t.ToEntityReference();
ssr.State = new OptionSetValue(0);
ssr.Status = new OptionSetValue(2);

SetStateResponse resp1 = (SetStateResponse)xrmConnection.Execute(ssr);

Use the following line of code to close task in CRM 2011
// close the task again.
SetStateRequest Closed = new SetStateRequest();
Closed.EntityMoniker = new EntityReference(t.LogicalName, t.Id);
Closed.State = new OptionSetValue(TaskClosedState);
Closed.Status = new OptionSetValue(TaskClosedStatus);

SetStateResponse resp2 = (SetStateResponse)xrmConnection.Execute(Closed);

No comments: