Asked by:
Need to start transaction before commit / -2147220911 / plugin MS CRM 2011

Question
-
Hi All,
I can't figure out with the following error:
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>2015-08-12T07:53:59.7922065Z</Timestamp>
<InnerFault i:nil="true" />
<TraceText i:nil="true" />
</OrganizationServiceFault>
This happens in a plugin on Post-Operation in Asynchronous & Synchronous mode.
The aim of this code is to move a code from a queue to another.
In the case from, i have a custom button that reactivates the case. This button launches my plugin & set the lookup field Queue to the default user's queue.
I tried to register the plugin in asynchronous or synchronous mode with no success..always the same error.
When I triy to update another kind of field (ie: dropdown) using the same code, it works fine :(
If anyone has an idea, i would appreciate a lot :D
Thanks for your help.
shoera
Wednesday, August 12, 2015 8:03 AM
All replies
-
Hello,
Could you please provide code of your plugin?
Recheck following link as well - https://social.microsoft.com/Forums/en-US/ca1301ca-cef9-4940-9cb4-e968641199f6/crm-2011-is-it-possible-to-catch-a-faultexception-and-stay-in-transaction?forum=crmdevelopment
Dynamics CRM MVP
My blogWednesday, August 12, 2015 8:22 AMModerator -
Hello,
Here's my code:
IPluginExecutionContext _context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
ITracingService _tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IOrganizationServiceFactory wod_serviceFactory = wod_serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService _crmService = wod_serviceFactory.CreateOrganizationService(_context.UserId);
EntityReference incidentRef = (EntityReference)_context.InputParameters["EntityMoniker"];
OptionSetValue state = (OptionSetValue)_context.InputParameters["State"];
OptionSetValue status = (OptionSetValue)_context.InputParameters["Status"];
//get PreImage
Entity PreImage = (Entity)_context.PreEntityImages["PreImage"];
if (state != null && state.Value == 0)
{
//move to another queue
Entity incidentToUpdate = new Entity("incident");
incidentToUpdate = _crmService.Retrieve(PreImage.LogicalName, PreImage.Id, new ColumnSet(true));
incidentToUpdate["ktb_queue"] = new EntityReference("queue", new Guid("765EE664-23F2-E311-A1BC-00237D31D7E6"));
incidentToUpdate["ktb_cards"] = true;
_crmService.Update(incidentToUpdate);
}
}thanks in advance,
shoera
Wednesday, August 12, 2015 8:45 AM -
Hello,
Do you have any plugins that handle update of ktb_queue and/or ktb_cards fields?
Also I suggest to rewrite your code to remove unneeded read:
IPluginExecutionContext _context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); ITracingService _tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); IOrganizationServiceFactory wod_serviceFactory = wod_serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService _crmService = wod_serviceFactory.CreateOrganizationService(_context.UserId); EntityReference incidentRef = (EntityReference)_context.InputParameters["EntityMoniker"]; OptionSetValue state = (OptionSetValue)_context.InputParameters["State"]; OptionSetValue status = (OptionSetValue)_context.InputParameters["Status"]; if (state != null && state.Value == 0) { //move to another queue Entity incidentToUpdate = new Entity("incident") { Id = incidentRef.Id }; incidentToUpdate["ktb_queue"] = new EntityReference("queue", new Guid("765EE664-23F2-E311-A1BC-00237D31D7E6")); incidentToUpdate["ktb_cards"] = true; _crmService.Update(incidentToUpdate); } }
Dynamics CRM MVP
My blogWednesday, August 12, 2015 9:02 AMModerator -
Hello,
Thank u for your reply but I get the same error.
It's quite difficult for me to find form which step the error occurs. (No doc...)
Anyway, there're 8 plugins on the entity incident.
1) ChangeOwner -> no step inside so i guess it's no longer in use ??? Plz, correct me if i'm wrong :-)
2) PostCreate -> Step (Event=Post-Operation, Execution Mode=Synchronous)
3) PostUpdae -> no step inside
4) PostUpdateAssync -> Step(Event=Post-Operation, Execution Mode=Synchronous)
5) Pre -> Create Step(Event=Pre-Operation, Execution Mode=Synchronous)
-> Update Step(Event=Post-Operation, Execution Mode=Synchronous)
6) PreUpdate -> Update Step(Event=Post-Operation, Execution Mode=Synchronous)
7) ReActivate -> SetState of incident Step(Event=Post-Operation, Execution Mode=Asynchronous)
-> SetStateDynamicEntity Step(Event=Post-Operation, Execution Mode=Synchronous)
8) RemoveWorkOn -> No step
The error occurs in in the SetStateDynamicEntity.
Thanks in Advance
Thursday, August 13, 2015 6:58 AM -
I believe issue comes from one of 2 following:
5) Pre -> Update Step(Event=Post-Operation, Execution Mode=Synchronous)
6) PreUpdate -> Update Step(Event=Post-Operation, Execution Mode=Synchronous)
Try to disable one of and reproduce your scenario. And after that I will need to see the source code of mentioned plugins.
Dynamics CRM MVP
My blogThursday, August 13, 2015 7:06 AMModerator