13 января 2012 г. 12:36
I am creating a plugin which will create custom entity. I have used "CreateCustomActivityEntity.cs" for help, this class is using OrganizationServiceProxy.execute and instead of that I am using IOrganizationService.execute. I am posting my code here. This code is generating this error when plugin fires - You cannot start a transaction with a different isolation level than is already set on the current transaction.// Obtain the execution context from the service provider.
var context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));I think I am doing something wrong because I am new in crm development and dobn't know how to use its classes. Please guide me why above code is not working. And just to fire my plugin I have registered it on account creation.Thanks in advance :)
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
// Create the custom activity entity.
CreateEntityRequest request = new CreateEntityRequest
HasNotes = true,
HasActivities = false,
PrimaryAttribute = new StringAttributeMetadata
SchemaName = "Subject",
RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
MaxLength = 100,
DisplayName = new Label("Subject", 1033)
Entity = new EntityMetadata
IsActivity = true,
SchemaName = "new_test",
DisplayName = new Label("Test", 1033),
DisplayCollectionName = new Label("Test", 1033),
OwnershipType = OwnershipTypes.UserOwned,
IsAvailableOffline = true,
service.Execute(request); // in sdk class its _serviceProxy.Execute(request);
26 января 2012 г. 1:20
Creating an entity/metadata through a plugin cannot be done. Within the same sql transaction you are attempting to use and create metadata. What is the scenario you are trying to do? Perhaps there is another way it can be achieved?
26 января 2012 г. 6:13МодераторI think there shoudl be a workaround to your problem - register the plugin to run asynchronously. This will take it out of the main transaction
Microsoft CRM MVP - http://mscrmuk.blogspot.com http://www.excitation.co.uk
- Изменено DavidJennawayMVP, Moderator 26 января 2012 г. 6:13
27 января 2012 г. 4:16I agree with you, I was doing it in wrong way. Thanks for reply :)
27 января 2012 г. 4:16
Thanks for reply, I will try your solution.
Thanks again :)
22 февраля 2012 г. 0:57
What was wrong in the solution ? How did u rectify the problem ?
22 февраля 2012 г. 5:18
I droped the idea to create custom entity through plugin because it was not feasible and I created it in my dummy solution using CRM UI. May be this can show you why my code was not working -
Sorry I can't help you with your problem because I am new to CRM development. Please post your problem as new Questiion so that CRM experts can help you with that. And please also post the Message, Stage and Execution mode in which you are registring your plugin, so that they can easily identify the issue.
- Изменено nmathur 22 февраля 2012 г. 5:19