Hello Guys,
when I try to create or update record from this plugin on realTime workflow that do the same job I get:
"There is no active transaction. This error is usually caused by custom plug-ins that ignore errors from service calls and continue processing"
using Innovation.Helper;
using Microsoft.Xrm.Sdk;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Innovation.PaymentEntity.RegularPayment
{
public class RegularPayment : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.InitiatingUserId);
CrmDataHelper CRM = new CrmDataHelper(service);
if (context.PostEntityImages.Contains("Post") && context.PostEntityImages["Post"] is Entity)
{
//Entity Entity = new Entity();
var Entity = (Entity)context.PostEntityImages["Post"];
//var current = context.InputParameters["Target"];
//var PreEntity = (Entity)context.PreEntityImages["Post"];
tracingService.Trace("created the image object");
// Check current transactions
var CurrentTransactions = CRM.RetrieveMultiple("inn_transactions", new string[] { "inn_paymententity" }, new string[] { Entity.Id.ToString() }, new string[] { });
tracingService.Trace("current transactions " + CurrentTransactions);
if (CurrentTransactions == null)
{
// Create Payment reqular
if ((Entity.GetAttributeValue<OptionSetValue>("inn_paymentstatus").Value != 121370002) & (Entity.GetAttributeValue<OptionSetValue>("inn_paymenttype").Value == 121370000))
{ //PaymentStatus == Paid && PaymentType == autopayment
tracingService.Trace("will create transaction");
Entity Transaction = new Entity("inn_transactions");
Transaction["inn_paymententity"] = new EntityReference(Entity.LogicalName, Entity.Id);
Transaction["inn_dateofpayment"] = DateTime.Now;
Transaction["inn_amount"] = (Entity.GetAttributeValue<Money>("inn_amount") != null) ? new Money(Entity.GetAttributeValue<Money>("inn_amount").Value) : new Money(0);
Transaction["inn_checknumber"] = (Entity.GetAttributeValue<string>("inn_checknumber") != null) ? Entity.GetAttributeValue<string>("inn_checknumber") : "";
Transaction["inn_chequedate"] = (Entity.GetAttributeValue<DateTime>("inn_chequedate") != null) ? Entity.GetAttributeValue<DateTime>("inn_chequedate") : DateTime.Now;
tracingService.Trace("just before execute create ");
CRM.CreateEntity(Transaction);
tracingService.Trace("created transaction");
tracingService.Trace("create payment regular");
var CurrentPaymentEntity = new Entity(Entity.LogicalName, Entity.Id);
CurrentPaymentEntity.Id = Entity.Id;
tracingService.Trace("current record " + CurrentPaymentEntity.LogicalName + " " + CurrentPaymentEntity.Id + " this is the id");
CurrentPaymentEntity["inn_paymentstatus"] = new OptionSetValue(121370002);
try { service.Update(CurrentPaymentEntity); }
catch (Exception ex) { throw new InvalidPluginExecutionException("error in update " + ex); } //it stucks here!!
//CRM.UpdateEntity(CurrentPaymentEntity);
tracingService.Trace("updated current entity");
}
}
}
else
{
throw new InvalidPluginExecutionException("doesn't contain image!!");
}
}
}
}
the error log
Unhandled exception:
Exception type: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]
Message: There is no active transaction. This error is usually caused by custom plug-ins that ignore errors from service calls and continue processing.Detail:
<OrganizationServiceFault xmlns:i="">www.w3.org/.../XMLSchema-instance" xmlns="">schemas.microsoft.com/.../Contracts">
<ActivityId>2b2983ac-def1-431b-af37-cef4c4a1f479</ActivityId>
<ErrorCode>-2147220911</ErrorCode>
<ErrorDetails xmlns:d2p1="">schemas.datacontract.org/.../System.Collections.Generic">
<KeyValuePairOfstringanyType>
<d2p1:key>ApiExceptionSourceKey</d2p1:key>
<d2p1:value xmlns:d4p1="">www.w3.org/.../XMLSchema" i:type="d4p1:string">Plugin/Microsoft.Crm.ObjectModel.CustomBusinessEntityService</d2p1:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<d2p1:key>ApiOriginalExceptionKey</d2p1:key>
<d2p1:value xmlns:d4p1="">www.w3.org/.../XMLSchema" i:type="d4p1:string">Microsoft.Crm.CrmException: There is no active transaction. This error is usually caused by custom plug-ins that ignore errors from service calls and continue processing. ---> Microsoft.Crm.CrmException: There is no active transaction. This error is usually caused by custom plug-ins that ignore errors from service calls and continue processing.
at Microsoft.Crm.CrmTransaction.CommitTransaction()
at Microsoft.Crm.LegacySqlDataAccessContextImplementation.CommitTransaction()
at Microsoft.Crm.Extensibility.MessageProcessor.Execute(PipelineExecutionContext context)
at Microsoft.Crm.Extensibility.InternalMessageDispatcher.Execute(PipelineExecutionContext context)
at Microsoft.Crm.Extensibility.ExtensiblePlatformMessageDispatcher.Execute(PipelineExecutionContext pluginContext)
at Microsoft.Crm.Extensibility.ExtensiblePlatformMessageDispatcher.UpdateWithInvocationSource(BusinessEntity entity, FilterExpression filter, Int32 invocationSource, ExecutionContext context)
at Microsoft.Crm.Extensibility.ExtensiblePlatformMessageDispatcher.Update(BusinessEntity entity, FilterExpression filter, ExecutionContext context)
at Microsoft.Crm.BusinessEntities.BusinessProcessObject.<>c__DisplayClass199_0.<UpdateWithPipelineAndExtensions>b__0()
at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute(ILogger logger, EventId eventId, ActivityType activityType, Action action, IEnumerable`1 additionalCustomProperties)
at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute(ILogger logger, XrmTelemetryActivityType activityType, Action action)
at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute(ILogger logger, EventId eventId, ActivityType activityType, Action action, IEnumerable`1 additionalCustomProperties)
at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute(ILogger logger, XrmTelemetryActivityType activityType, Action action)
--- End of inner exception stack trace ---
at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)
at Microsoft.Crm.Extensibility.PipelineInstrumentationHelper.Execute(Boolean instrumentationEnabled, String stopwatchName, ExecuteWithInstrumentation action, PipelineExecutionContext context)
at Microsoft.Crm.Extensibility.Pipeline.<>c__DisplayClass2_1.<Execute>b__0()</d2p1:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<d2p1:key>ApiStepKey</d2p1:key>
<d2p1:value xmlns:d4p1="">www.w3.org/.../XMLSchema" i:type="d4p1:string">fb0227d4-37c2-e811-a94d-000d3aba6816</d2p1:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<d2p1:key>ApiDepthKey</d2p1:key>
<d2p1:value xmlns:d4p1="">www.w3.org/.../XMLSchema" i:type="d4p1:string">3</d2p1:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<d2p1:key>ApiActivityIdKey</d2p1:key>
<d2p1:value xmlns:d4p1="">www.w3.org/.../XMLSchema" i:type="d4p1:string">59d41de1-ccd8-42f1-bfe6-fd3e4da170f2</d2p1:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<d2p1:key>ApiPluginSolutionNameKey</d2p1:key>
<d2p1:value xmlns:d4p1="">www.w3.org/.../XMLSchema" i:type="d4p1:string">System</d2p1:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<d2p1:key>ApiStepSolutionNameKey</d2p1:key>
<d2p1:value xmlns:d4p1="">www.w3.org/.../XMLSchema" i:type="d4p1:string">System</d2p1:value>
</KeyValuePairOfstringanyType>
</ErrorDetails>
<Message>There is no active transaction. This error is usually caused by custom plug-ins that ignore errors from service calls and continue processing.</Message>
<Timestamp>2019-07-03T12:25:31.9321853Z</Timestamp>
<ExceptionRetriable>false</ExceptionRetriable>
<ExceptionSource i:nil="true" />
<InnerFault i:nil="true" />
<OriginalException i:nil="true" />
<TraceText>
[Innovation.PaymentEntity.RegularPayment: Innovation.PaymentEntity.RegularPayment.RegularPayment]
[881c6fac-8b9d-e911-a81d-000d3ab35b39: Innovation.PaymentEntity.RegularPayment.RegularPayment: Update of inn_paymententity]
created the image object
current transactions
will create transaction
just before execute create
[Innovation.Transaction.Payment: Innovation.Transaction.Payment.Payment]
[df1b9779-832f-e811-a955-000d3a209848: Innovation.Transaction.Payment.Payment: Create of inn_transactions]
</TraceText>
</OrganizationServiceFault>
*This post is locked for comments