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

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Message Delete is not working as expected

(0) ShareShare
ReportReport
Posted on by 35

Hi,

I have table  "Test", and I need to calculate the score in another table based on the number of items of "Test" table .
I wrote a plugin that needs to execute when some entries in the test table is deleted  and I have registered plugin..But that plugin isn't running, it's not even showing error.
Need help in making this plugin run.

Thanks,

I have the same question (0)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Message Delete is not working as expected

    Hello,

    Can you please provide the code of your plugin and a screenshot of a registration step?

  • Praajna Profile Picture
    35 on at
    RE: Message Delete is not working as expected

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Query;
    using System.ServiceModel;

    namespace Honeywell
    {
    public class DeletePlugintest : IPlugin
    {
    public void Execute(IServiceProvider serviceProvider)
    {
    ITracingService tracingService =
    (ITracingService)serviceProvider.GetService(typeof(ITracingService));

    // Obtain the execution context from the service provider.
    IPluginExecutionContext context = (IPluginExecutionContext)
    serviceProvider.GetService(typeof(IPluginExecutionContext));

    // 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);

    // IOrganizationService adminservice = serviceFactory.CreateOrganizationService(new Guid(""));

    // 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 siteYb = (Entity)context.InputParameters["Target"];


    try
    {
    throw new System.Exception("Delete is Working");
    }

    catch (FaultException<OrganizationServiceFault> ex)
    {
    throw new InvalidPluginExecutionException("An error occurred in MyPlug-in.", ex);
    }

    catch (Exception ex)
    {
    tracingService.Trace("MyPlugin: {0}", ex.ToString());
    throw;
    }
    }
    }

    }
    }

    0523.Screenshot-_2800_26_2900_.png

    i throwed an error in my plugin which was registered as a step against message on delete , and i didnt get any error confirming my plugin wasnt executed on delete . steps which was registered against create and update are working fine except delete

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Message Delete is not working as expected

    So the issue you experience is related to the following lines:

    if (context.InputParameters.Contains("Target") &&

    context.InputParameters["Target"] is Entity)

    when the Delete message is executed - Target is of type of EntityReference and not Entity.

    Good luck.

  • Suggested answer
    Praajna Profile Picture
    35 on at
    RE: Message Delete is not working as expected

    Hey Thanks a lot ... It's working now

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 258

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 179

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 128 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans