Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Disable All the steps in a Plug

Posted on by 395

Hi,

I am trying to disable all the plug-in steps under a plug-in because of one processing scenario. I am able to disable individually but I want to disable all the steps under the plug-in with one call. Is there any better approach other than below one. Below one is just a sample code to disable one step similar way I want to disable all the steps under that plug-in.

var qe = new QueryExpression("sdkmessageprocessingstep");

qe.ColumnSet.AddColumns("sdkmessageprocessingstepid", "name");

var step = orgService.RetrieveMultiple(qe).Entities.Where(x => x.Attributes["name"].ToString().Contains(pluginName)).First();

//Trying to retrieve but not sure how to update all the steps under this Step1 using one call

//var step1 = orgService.RetrieveMultiple(qe).Entities.Where(x => x.Attributes["name"].ToString().Contains(pluginName));

var pluginId = (Guid)step.Attributes["sdkmessageprocessingstepid"];

int pluginStateCode = enable ? 0 : 1;

int pluginStatusCode = enable ? 1 : 2;

orgService.Execute(new SetStateRequest

{

EntityMoniker = new EntityReference("sdkmessageprocessingstep", pluginId),

State = new OptionSetValue(pluginStateCode),

Status = new OptionSetValue(pluginStatusCode)

});

*This post is locked for comments

  • Suggested answer
    Daryl LaBar Profile Picture
    Daryl LaBar 500 Most Valuable Professional on at
    RE: Disable All the steps in a Plug

    No Code solution:

    1 - Install XrmToolBox (https://www.xrmtoolbox.com/) and the SQL 4 CDS tool (markcarrington.dev/.../)

    2 - Open the tool and connect to your org.

    3 - Run this SQL to enable all plugin steps that start with your desired name ("MyPrefix." In this case):

    UPDATE sdkmessageprocessingstep
    SET statecode = 0, statuscode = 1
    WHERE sdkmessageprocessingstepid in (
        SELECT step.sdkmessageprocessingstepid FROM sdkmessageprocessingstep step
        INNER JOIN plugintype ON step.eventhandler = plugintype.plugintypeid
        WHERE pluginType.name like 'MyPrefix.%' AND Statecode = 1
    )

    Or this to disable them:

    UPDATE sdkmessageprocessingstep
    SET statecode = 1, statuscode = 2
    WHERE sdkmessageprocessingstepid in (
        SELECT step.sdkmessageprocessingstepid FROM sdkmessageprocessingstep step
        INNER JOIN plugintype ON step.eventhandler = plugintype.plugintypeid
        WHERE pluginType.name like 'MyPrefix.%' AND Statecode = 0
    )

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Disable All the steps in a Plug

    In addition to Alex's answer, just an brief explanation:

    Your code basically seems fine with the exception that you are calling a First method after calling the Retrieve Multiple.

    You need to do a For Each statement on the Retrieve Multiple Results of the Entity Collection.

    Basically:

    EntityCollection steps = orgService.RetrieveMultiple(qe).Entities.Where(x => x.Attributes["name"].ToString().Contains(pluginName));

    foreach (Entity step in steps.Entities)

    {

      Guid stepId = step.Id;

      int pluginStateCode = enable ? 0 : 1;

      int pluginStatusCode = enable ? 1 : 2;

      DeactivateStep (stepId, pluginStateCode, pluginStatusCode);

    }

    // function to Deactivate Each Step

    private function DeactivateStep(Guid stepId, int pluginStateCode, int pluginStatusCode)

    {

      SetStateRequest request = new SetStateRequest()

      {

         EntityMoniker = new EntityReference("sdkmessageprocessingstep", pluginId),

         State = new OptionSetValue(pluginStateCode),

         Status = new OptionSetValue(pluginStatusCode)

      };

      orgService.Execute(request);

    }

    Hope this helps.

  • Srini20 Profile Picture
    Srini20 395 on at
    RE: Disable All the steps in a Plug

    Thanks Alex.

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: Disable All the steps in a Plug

    They are just records in Dynamics, so you have to work with them the same way you work with everything else (one after another). You might try using ExecuteMultipleRequest, but, essentially, it's still going to be one-after-another, you'll just batch all those individual requests through a single call to the org service.

    https://msdn.microsoft.com/en-us/library/microsoft.xrm.sdk.messages.executemultiplerequest.aspx

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

Featured topics

Product updates

Dynamics 365 release plans