We see that Update PreOperation Plugin gets called multiple times.
Scenario - Quote is updated by adding a Product Line. We see that there is only one update in audit log.
, But unable to figure out why there are many calls to our UpdateTestPlugin which is configured as
UpdateTestPlugin Code is very simple one, to get the tracing service and add attributes from entity.
Code below.
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
// The InputParameters collection contains all the data passed in the message request.
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parameters.
Entity entity = (Entity)context.InputParameters["Target"];
// Obtain the organization service reference which you will need for
// web service calls.
IOrganizationServiceFactory serviceFactory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
try
{
// Plug-in business logic goes here.
tracingService.Trace("inside update test plugin");
Entity entityFromContext = (Entity)context.InputParameters["Target"];
foreach (String key in entityFromContext.Attributes.Keys)
{
tracingService.Trace($"{key} " + "value " + entityFromContext.Attributes[key]);
}
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("An error occurred in FollowUpPlugin.", ex);
}
catch (Exception ex)
{
tracingService.Trace("FollowUpPlugin: {0}", ex.ToString());
throw;
}
}