Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

dynamically/programatically enable/disable plugin?

Posted on by Microsoft Employee

Hello, I have a scheduled job that I need to run nightly. This job requires that one of the plugin entities be disabled before the job starts and re-enabled when the job ends. I need to run this job at night (independently) so I'm trying to figure out if there's a way to dynamically/programatically enable/disable a plugin through a console app.  Do you know if this is possible and how to do this?

*This post is locked for comments

  • Peter Hegyesi Profile Picture
    Peter Hegyesi 5 on at
    RE: dynamically/programatically enable/disable plugin?

    I would suggest to add a criteria instead of a Where linq on the whole resultset.

    qe.Criteria.AddCondition("name", ConditionOperator.Equal, pluginName);

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: dynamically/programatically enable/disable plugin?

    Thanks a lot Guido.  That was exactly what I was looking for.  I consolidated the code at that url into the simplified utility method below:

           public void EnablePlugin(IOrganizationService orgService, bool enable, string pluginName)

           {

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

               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)

               });

           }

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