We upgraded to CRM 365 on-premise (8.2.2) and we are using custom code to deactivate users, (to move data to another user and other things). In the end, we use this example code: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/sample-disable-user But that no longer works for us after the upgrade.
Now we get '-1 is not a valid state code on mailbox with Id ' and looking at the error on the server it looks like this:
[2018-09-17 08:07:45.297] Process: w3wp |Organization: |Thread: 9 |Category: Platform.Sdk |User: |Level: Error |ReqId: 129694cd-1d73-4723-8d3e-ca9487294697 |ActivityId: ad01991a-c02a-4f1e-9db1-3a936a432752 | VersionedPluginProxyStepBase.Execute ilOffset = 0x64
Web Service Plug-in failed in SdkMessageProcessingStepId: {57CDBB1B-EA3E-DB11-86A7-000A3A5473E8}; EntityName: systemuser; Stage: 30; MessageName: SetStateDynamicEntity; AssemblyName: Microsoft.Crm.Extensibility.InternalOperationPlugin, Microsoft.Crm.ObjectModel, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35; ClassName: Microsoft.Crm.Extensibility.InternalOperationPlugin; Exception: Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Web.Services.Protocols.LogicalMethodInfo.Invoke(Object target, Object[] values) at Microsoft.Crm.Extensibility.InternalOperationPlugin.Execute(IServiceProvider serviceProvider) at Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext context) at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context) Inner Exception: Microsoft.Crm.CrmArgumentException: -1 is not a valid state code on mailbox with Id . at Microsoft.Crm.BusinessEntities.StatusCodeValidator.Validate(EntityMetadata entityMetadata, Int32 stateCode, Int32 statusCode, Guid businessEntityId) at Microsoft.Crm.BusinessEntities.BusinessProcessObject.SetState(BusinessEntityMoniker moniker, Int32 newState, Int32 newStatusCode, BusinessEntity originalEntity, ExecutionContext context) at Microsoft.Crm.BusinessEntities.BusinessProcessObject.SetState(BusinessEntityMoniker moniker, Int32 newState, Int32 newStatusCode, ExecutionContext context) at Microsoft.Crm.ObjectModel.MailboxServiceInternal
1.SetState(BusinessEntityMoniker moniker, Int32 newState, Int32 newStatusCode, ExecutionContext context) at Microsoft.Crm.ObjectModel.SystemUserServiceInternal
1.SetMailboxState(BusinessEntityMoniker moniker, Int32 newState, Int32 newStatusCode, ExecutionContext context) at Microsoft.Crm.ObjectModel.SystemUserServiceInternal`1.SetState(BusinessEntityMoniker moniker, Int32 newState, Int32 newStatusCode, ExecutionContext context) at Microsoft.Crm.ObjectModel.SystemUserService.Microsoft.Crm.Sdk.IStateful.SetStateStatus(BusinessEntityMoniker , Int32 , Int32 , ExecutionContext ) Inner Exception: System.ArgumentException: -1 is not a valid state code on mailbox with Id . Parameter name: stateCode
So I tried to deactivate the user mailboxes first, but it does not help. Still the same issue. Anyone have the same issue and resolved it somehow?