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
I would suggest to add a criteria instead of a Where linq on the whole resultset.
qe.Criteria.AddCondition("name", ConditionOperator.Equal, pluginName);
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)
});
}
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156