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 CRM (Archived)

Disable All the steps in a Plug

(0) ShareShare
ReportReport
Posted on by 397

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

I have the same question (0)
  • Suggested answer
    ashlega Profile Picture
    34,477 on at

    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

  • Srini20 Profile Picture
    397 on at

    Thanks Alex.

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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.

  • Suggested answer
    Daryl LaBar Profile Picture
    500 Most Valuable Professional on at

    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
    )

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 CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans