Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

Message Delete is not working as expected

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,

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

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

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 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.

  • Praajna Profile Picture
    Praajna 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

  • a33ik Profile Picture
    a33ik 84,323 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?

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans