I got this error when I try to reopen appointment: "Cannot update Closed or Cancelled Activity" here is my code:
var connectionString = ConfigurationManager.ConnectionStrings["crmConnection"].ConnectionString;
var conn = CrmConnection.Parse(connectionString);
var service = new OrganizationService(conn);
var stateRequest = new SetStateRequest
{
State = new OptionSetValue(0),
Status = new OptionSetValue(1),
EntityMoniker = entity.ToEntityReference()
};
service.Execute(stateRequest);
I'm getting the entity from RetrieveMultiple(query)
where StateCode
is "Cancel" or "Complete". I run this code in a Console Application and get that error.
PS: I wrote my code in the new version but I got this error again:
entity.SetAttributeValue<OptionSetValue>("statecode", 0);
entity.SetAttributeValue<OptionSetValue>("statuscode", 1);
var request = new UpdateRequest { Target = entity };
var response = (UpdateResponse)_organizationService.Execute(request);
Finally, after 8 hours working I got it!. It's so ridiculous but it worths to know. this error raises from another plugin that I had registered before. That plugin was registered on "Update" message when "StateCode" field has changed. I disable that step and my deprecate function has worked! in exception message, you cannot understand which plugin raise the error.