I am creating a plugin where I need to change a field of multiple appointments in CRM, but when I try to open the appointment I get the message "Cannot update Closed or Cancelled Activity". can anybody help me?
setState(0, 1, newEntity.ToEntityReference(), service, item.LogicalName, erro); newEntity[attributte] = new EntityReference(Account.LogicalName, Account.Id); service.Update(newEntity); setState(((OptionSetValue)savedState["statecode"]).Value, ((OptionSetValue)savedState["statuscode"]).Value, newEntity.ToEntityReference(), service, item.LogicalName, erro); public void setState(int stateCode, int statusCode, EntityReference entity, IOrganizationService service, string entityName, string erro) { SetStateRequest state = new SetStateRequest(); // Set the Request Object's Properties state.State = new OptionSetValue((int)stateCode); state.Status = new OptionSetValue((int)statusCode); // Point the Request to the case whose state is being changed state.EntityMoniker = entity; // Execute the Request SetStateResponse stateSet = (SetStateResponse)service.Execute(state); }