Recently we had to disable plugin steps as part of data migration, below is the sample code we can use, either specify the name of the assembly, plugin, or plugin step as we are using the “begins with” condition or make changes as required.
class Program
{
static void Main(string[] args)
{
const string ConnectionString = "AuthType = OAuth; " +
"Username = Nishant.Rana@xyz.com; " +
"Password = testxyz; " +
"Url = https://orgname.crm6.dynamics.com;" +
"AppId=51f81489-12ee-4a9e-aaae-a2591f45987d;" +
"RedirectUri=app://58145B91-0C36-4500-8554-080854F2AC97;" +
"LoginPrompt=Auto";
CrmServiceClient svc = new CrmServiceClient(ConnectionString);
if (svc.IsReady)
{
try
{
// we can specify step / plugin / assembly name
var pluginStepAssemblyName = "MyD365.Plugins.Core.Plugin.AssignOwner";
// 0 for active and 1 for inactive
var pluginStateCode = 0;
var query = new QueryExpression("sdkmessageprocessingstep");
query.ColumnSet = new ColumnSet("name", "sdkmessageprocessingstepid");
query.Criteria.AddCondition(new ConditionExpression("name", ConditionOperator.BeginsWith, pluginStepAssemblyName));
var sdkMsgProcessStepCollection = svc.RetrieveMultiple(query);
foreach (var sdkMsgProcessStep in sdkMsgProcessStepCollection.Entities)
{
var setStateRequest = new SetStateRequest();
setStateRequest.EntityMoniker = new EntityReference("sdkmessageprocessingstep", sdkMsgProcessStep.Id);
setStateRequest.State = new OptionSetValue(pluginStateCode);
setStateRequest.Status = new OptionSetValue(-1);
svc.Execute(setStateRequest);
}
}
catch (Exception ex)
{
Console.WriteLine("Exception Messainge : {0} ", ex.Message);
}
}
}
}
Hope it helps..
One thought on “Sample Code – Enable / Disable Plugin Step (sdkmessageprocessingstep) Dynamics 365 / Dataverse”