Announcements
I have a plugin that is executed when a new instance from the sales order detail entity is created, it updates a field in the form. when creating the instance an error appears in the plugin trace log:
get Ref
productIdRef
de_prdrate: 19
de_salesprdrate: 19
System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]:
An error occurred in FollowUpPlugin. (Fault Detail is equal to
Exception details: ErrorCode: 0x80040265 Message: An error occurred in
FollowUpPlugin.
OriginalException: PluginExecution ExceptionSource: PluginExecution
Note: there is also a System workflow running on the sales order detail entity on the create event. the plugin works fine on the quote details entity without any exceptions or errors.
I think the problem is that my plugin and the system workflow work on the same event. I did not find any solution to this problem. I appreciate any suggestions.
The code is below:
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
namespace Orders_Plugins
{
public class Update_Salesdetails_Field : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
IOrganizationServiceFactory serviceFactory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
try
{
if (entity.LogicalName != "salesorderdetail")
{
tracingService.Trace("Target entity is not Sales Order Detail! plug-in was not registered correctly! Exit PlugIn", serviceProvider);
throw new InvalidPluginExecutionException("The current entity is not the Sales Order Detail entity");
}
else
{
tracingService.Trace("get Ref", serviceProvider);
var productIdRef = entity.GetAttributeValue<EntityReference>("productid");
tracingService.Trace("productIdRef", serviceProvider);
var productEntity = service.Retrieve("product", productIdRef.Id, new ColumnSet("de_prdrate"));
tracingService.Trace("de_prdrate: " + productEntity["de_prdrate"].ToString(), serviceProvider);
entity["de_salesprdrate"] = productEntity["de_prdrate"];
tracingService.Trace("de_salesprdrate " + entity["de_salesprdrate"].ToString(),
service.Update(entity);
tracingService.Trace("Update salesprdrate " + entity["de_salesprdrate"].ToString(),
}
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("An error occurred in FollowUpPlugin.", ex);
tracingService.Trace("exception:", ex.ToString());
}
catch (Exception ex)
{
tracingService.Trace("FollowUpPlugin: {0}", ex.ToString());
throw;
}
}
}
}
}
I found the solution it was the plugin execution stage it should be in the pre stages and not in post
Strange. Need to check
Thanks Pradeep Rai for your response, I made the changes in the catch block as you suggested. the error message became clear.
it said : "The product and the unit cannot be updated while the entity is locked ".
I made some changes in the code based on the following links but it did not work for me.
the changes of code is in the images below:
Hi,
Please update the case block code. For better error message please Message object as shown below:
After this. Try disabling your workflow and run plugin. If plugin works properly then try by changing execution order of plugin as described in below links:
https://medium.com/@ras615/plugin-vs-workflow-execution-order-fa6b02c82b79
André Arnaud de Cal...
294,261
Super User 2025 Season 1
Martin Dráb
232,996
Most Valuable Professional
nmaenpaa
101,158
Moderator