Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Dynamics 365 Plugin An error occurred in FollowUpPlugin 0x80040265

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;
                }
            }
        }

    }


}
  • Suggested answer
    AlloyloD365 Profile Picture
    AlloyloD365 5 on at
    RE: Dynamics 365 Plugin An error occurred in FollowUpPlugin 0x80040265

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

  • Pradeep Rai Profile Picture
    Pradeep Rai 5,490 Super User 2024 Season 2 on at
    RE: Dynamics 365 Plugin An error occurred in FollowUpPlugin 0x80040265

    Strange. Need to check

  • AlloyloD365 Profile Picture
    AlloyloD365 5 on at
    RE: Dynamcs 365 Plugin An error occurred in FollowUpPlugin 0x80040265

    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

  • Suggested answer
    Pradeep Rai Profile Picture
    Pradeep Rai 5,490 Super User 2024 Season 2 on at
    RE: Dynamcs 365 Plugin An error occurred in FollowUpPlugin 0x80040265

    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

       

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans