web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

Dynamics 365 Plugin An error occurred in FollowUpPlugin 0x80040265

(0) ShareShare
ReportReport
Posted on by 5

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 have the same question (0)
  • Suggested answer
    Pradeep Rai Profile Picture
    5,489 Moderator on at

    Hi,

    Please update the case block code. For better error message please Message object as shown below:

    pastedimage1675707722351v1.png

    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

       

  • AlloyloD365 Profile Picture
    5 on at

    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.

    (+) Error "The product and the unit cannot be updated while the entity is locked" when creating Order Product - Microsoft Dynamics CRM Forum Community Forum

    (+) Quote to Order Workflow prevents Plugin from firing - Microsoft Dynamics CRM Forum Community Forum

    My CRM Stuff: c# plugin update error The product and the unit cannot be updated while the entity is locked. (nzcrmguy.blogspot.com)

    the  changes of code is in the images below: 

    new-code.png

    newcode01.png

  • Pradeep Rai Profile Picture
    5,489 Moderator on at

    Strange. Need to check

  • Suggested answer
    AlloyloD365 Profile Picture
    5 on at

    I found the solution it was the plugin execution stage  it should be in the pre stages and not in post

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 41 Most Valuable Professional

#2
iampranjal Profile Picture

iampranjal 39

#3
Satyam Prakash Profile Picture

Satyam Prakash 35

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans