Answered by:
Outlook error when attempting to track an item in Microsoft Dynamics CRM 2011 when contact does not exists in CRM 2011

Question
-
Hi All,
In CRM2011 when I try to track an email from a non existing contact. I get the following error.
An error occurred promoting this item to Microsoft Dynamics CRM. The Microsoft Dynamics CRM server could not be contacted or the user has insufficient permissions to perform this action.
As you know the email should be tracked on the record that it is tracked for(For example Case 1) --> This
When I look in CRM
-the email was tracked correctly in CRM for that particular entity (For example Case 1)
- but the contact failed to be created. So it seems that for some reason CRM cannot create that contact who sent the email and does not exist in CRM.
When I run the trace on outlook client. I get the following 3 errors
Error1:
TraceException: Unhandled Exception: System.Runtime.InteropServices.COMException: Need to start a transaction before commit
at Microsoft.Crm.Application.SMWrappers.CrmServiceForOutlook.Execute(OrganizationRequest request, Boolean wrapException)
at Microsoft.Crm.Application.SMWrappers.EmailForOutlook.Microsoft.Crm.Application.SMWrappers.IEmailForOutlook.DeliverPromote(String messageId, String subject, String from, String to, String cc, String bcc, Double receivedon, String submittedBy, String importance, String body, IDynamicEntityCollectionForOutlook attachments, Int32 attachmentCount, String entityXml, String regardingId, Int64 regardingObjectType, String crmId, Int32& notification)Error2:
Entity id is null or empty, skip deleting the entity 'email'
Error 3:
CrmServiceForOutlook.Execute
at CrmServiceForOutlook.Execute(OrganizationRequest request, Boolean wrapException)
at EmailForOutlook.Microsoft.Crm.Application.SMWrappers.IEmailForOutlook.DeliverPromote(String messageId, String subject, String from, String to, String cc, String bcc, Double receivedon, String submittedBy, String importance, String body, IDynamicEntityCollectionForOutlook attachments, Int32 attachmentCount, String entityXml, String regardingId, Int64 regardingObjectType, String crmId, Int32& notification)
FaultExceptionDetails: Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Need to start a transaction before commitDetail:
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
<ErrorCode>-2147220911</ErrorCode>
<ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
<Message>Need to start a transaction before commit</Message>
<Timestamp>2014-10-03T21:14:43.7395959Z</Timestamp>
<InnerFault i:nil="true" />
<TraceText i:nil="true" />
</OrganizationServiceFault>
Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.Xrm.Sdk.IOrganizationService.Execute(OrganizationRequest request)
at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.ExecuteCore(OrganizationRequest request)
at Microsoft.Crm.Application.SMWrappers.ClientOrganizationServiceProxy.ExecuteCore(OrganizationRequest request)
at Microsoft.Crm.Application.SMWrappers.CrmServiceForOutlook.Execute(OrganizationRequest request, Boolean wrapException)
I do appropriate any advice.
Thanks,
Maryam
Friday, October 3, 2014 10:41 PM
Answers
-
Thank you guys for your help. The issue is fixed. We installed Rollup 16 on client and it seems working. Thanks for all your help
- Marked as answer by Maryam_r Tuesday, November 18, 2014 1:00 AM
Tuesday, November 18, 2014 1:00 AM
All replies
-
Hi Maryam,
please check if any of your plugin is catching exception and and not processing it properly or hiding it?
Friday, October 3, 2014 10:51 PM -
Thanks so much for the response.
I have only on plugin running on contact, Which validate a value of a custom field if it is not empty. For the above issue the value of this field is empty as the contact is created automatically.
Is it possible that I am missing any security setting?
Thanks,
Monday, October 6, 2014 4:24 PM -
Hi, Your plugin might be throwing an exception and losing the transaction context. Could you please post the section of code?. You could modify the section of code to insert a default value when the field is empty based on the business requirement. Regards JitheshMonday, October 6, 2014 9:45 PM
-
Hi,
Below please find the code for the contact plugin.
Back to your point it should not through any error. If it does something is wrong with my plugin perhaps. Also there is no business rule to insert a default value .
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using System.Text.RegularExpressions;
using Microsoft.Xrm.Sdk.Query;
namespace Contact.Validation
{
/
public class ContactValidation :IPlugin
{
const string entityName = "contact";
#region Iplugin Member
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the execution context from the service provider.
var context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var service = serviceFactory.CreateOrganizationService(context.UserId);
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
if (tracingService == null)
{
throw new InvalidPluginExecutionException("Failed to retrieve tracing service in ContactValidation plugin. Please contact your administartior.");
}
//Verify message context
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity &&
context.PrimaryEntityName == entityName)
{
Entity entity = (Entity)context.InputParameters["Target"];
//Check UniqueId
if (entity.Attributes.Contains("pcx_UniqueId"))
{
string UniqueId = entity.Attributes["pcx_UniqueId"].ToString();
tracingService.Trace("UniqueId is set to: " + UniqueId);
Regex regex = new Regex(@"\d{9}");
if (!(regex.IsMatch(UniqueId)))
{
throw new InvalidPluginExecutionException("The UniqueId must be a 9 digit number");
}
//Check Contact duplication
var fetchXml = string.Format(@"
<fetch mapping='logical' aggregate='true'>
<entity name='contact'>
<attribute name='contactid' aggregate='count' alias='count'/>
<filter>
<condition attribute='pcx_UniqueId' operator='eq' value='{0}'/>
</filter>
</entity>
</fetch>", UniqueId);
EntityCollection queryResult = service.RetrieveMultiple(new FetchExpression(fetchXml));
bool hasDuplicateUniqueId = (int)(((AliasedValue)queryResult[0]["count"]).Value) > 0 ? true : false;
if (hasDuplicateUniqueId)
{
tracingService.Trace("There is/are " + (int)(((AliasedValue)queryResult[0]["count"]).Value) + " contacts with the same UniqueId.");
throw new InvalidPluginExecutionException("Another Contact already exists with the same UniqueId.");
}
}
}
else
{
throw new InvalidPluginExecutionException("ContactValidation plugin is not registered correctly. Please contact your system administrator.");
}
}
#endregion Iplugin Member
}
}
Tuesday, October 7, 2014 12:05 AM -
Hi Maryam,
you have to debug the plugin to find what is happening. or look at the traces - to check where the exception is triggered. One possibility is the string is null and throwing exception
Either
// replace if (!(regex.IsMatch(UniqueId))) // with if (!string.IsNullOrEmpty(UniqueId) || (!(regex.IsMatch(UniqueId)))
Or convert the uid to int.
Int32 UniqueId = entity.GetAttributeValue<Int32>("pcx_UniqueId");
and compare.
Regards,
Jithesh
Tuesday, October 7, 2014 12:40 AM -
Hi Maryam,
you have to debug the plugin to find what is happening. or look at the traces - to check where the exception is triggered. One possibility is the string is null and throwing exception
Either
// replace if (!(regex.IsMatch(UniqueId))) // with if (!string.IsNullOrEmpty(UniqueId) || (!(regex.IsMatch(UniqueId)))
Or convert the uid to int.
Int32 UniqueId = entity.GetAttributeValue<Int32>("pcx_UniqueId");
and compare.
Regards,
Jithesh
Please feel free to contact me via any of the following methods:
Tuesday, October 7, 2014 8:25 AM -
But this senario can not happen because in My code I am checking
if (entity.Attributes.Contains("pcx_UniqueId")) then perform the Logic
Also if you look at the 3 errors that I post above none of them are very meaningfull to me.
I wonder if I am missing any security configuration that is causing this issue?
Also for debugging I need to have Visual studio on the client machine. I don't have at at the moment :(
- Edited by Maryam_r Friday, October 10, 2014 1:38 AM
Friday, October 10, 2014 12:04 AM -
Thanks so much for the response.
I have only on plugin running on contact, Which validate a value of a custom field if it is not empty. For the above issue the value of this field is empty as the contact is created automatically.
Is it possible that I am missing any security setting?
Thanks,
You have already specified that the code works well when the value if field is empty. Why do you suspect security issue?
please see the verified answer for the following post.
https://community.dynamics.com/crm/f/117/t/126572.aspx
similar to my reply( int used in my sample, you can turn this to string if you wish)
Regards,
Jithesh
Friday, October 10, 2014 11:42 AM -
Thank you guys for your help. The issue is fixed. We installed Rollup 16 on client and it seems working. Thanks for all your help
- Marked as answer by Maryam_r Tuesday, November 18, 2014 1:00 AM
Tuesday, November 18, 2014 1:00 AM