2

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);
Nader Vaghari
  • 141
  • 10
  • As per [this article](https://learn.microsoft.com/en-us/dynamics365/customer-engagement/developer/org-service/perform-specialized-operations-using-update) `SetStateRequest` is deprecated. – Aron Oct 02 '18 at 18:16
  • I think it's not related to depreciation because I wrote my code in the new version and I got same error too – Nader Vaghari Oct 03 '18 at 07:29

2 Answers2

1

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.

Nader Vaghari
  • 141
  • 10
0

Please provide the total code. I see here, you statened a new OrganizationService, as you have used one before (for retrieveMultiple).

Maybe using the same service, just fixes your problem :), but with total code we can maybe help more.

In addiont to the deprecated discussion. You use CRM 2015, as it seems to be flagged with it? It is only depricated in D365 as i know (hopefully i am not mistaken here ;) )