CAN’T DELETE AN EMAIL FROM MICROSOFT DYNAMICS CRM 2011

Some days ago, I faced an issue regarding CRM audit feature. A customer was unable to close an active case since there was an open activity related to it. Then I told him to close all open activities before closing a case because that`s the way it works. However, he was unable to close the activity because CRM had experienced an error.

The activity that my customer was trying to close was a draft email (in fact, he wanted to delete the email, but he was unable to, though). When I took a look at it, I found that some recipients (highlighted in red) were not resolved in CRM.The exception was related to the Audit feature enabled by me a couple of days before the user had this error. The plug-in that registers the changes on the entities tried to establish a relationship between the recipients of the e-mail (fields To, CC and BCC) and some existent contact or account in CRM, which in fact, they don't exist in CRM.Just by looking at the server log, you can confirm this: 

“The Web Service plug-in failed in OrganizationId: 0d469757-a137-46d1-8f38-12a6d65f79a5; SdkMessageProcessingStepId: b92673ed-dc92-442b-a6c6-82f2fce14585; EntityName: email; Stage: 25; MessageName: Delete; AssemblyName: Microsoft.Crm.AuditMonikerMessagesPlugin, Microsoft.Crm.Audit, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35; ClassName: Microsoft.Crm.AuditMonikerMessagesPlugin; Exception: Unhandled Exception: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at Microsoft.Crm.AuditHelper.GetXrmValue(Object attribute)
at Microsoft.Crm.AuditMonikerMessagesPlugin.BuildDeleteData(StringBuilder attributeMaskBuilder, StringBuilder changeDataBuilder, Entity preEntity, EntityMetadata entityMetadata, IPluginExecutionContext context)
at Microsoft.Crm.AuditMonikerMessagesPlugin.BuildChangeData(String& attributeMask, EntityMetadata entityMetadata, IPluginExecutionContext context)
at Microsoft.Crm.AuditBase.LogAuditData(IPluginExecutionContext context, Guid objectId, Boolean allowEntityOnlyAudit, Entity entity, EntityMetadata entityMetadata)
at Microsoft.Crm.AuditMonikerMessagesPlugin.Execute(IServiceProvider serviceProvider)
at Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext context)
at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)

My workaround to this problem was to disable the audit feature for the fields To, CC and BCC of the e-mail entity.

I hope this helps.

Nicolás Brandl

No Comments