i need to execude some actions on wf instances in sharepoint online, but i cant get to the instances, i have a method which is pretty self explanatory. No matter what i tried, instancesCount is always zero.
this SO question was solved, but is uses JSOM, while i am using console application.
I even tried powershell, different Microsoft.SharePoint.Client.WorkflowServices dll version, and all the methods available on WorkflowInstanceService.
public static void ShowWorkflowsWithStatus(Web web, string wfSubscriptionName, WorkflowStatus status)
{
var workflows = web.WorkflowAssociations;
var svcManager = new WorkflowServicesManager(web.Context, web);
var wfInstancesManager = svcManager.GetWorkflowInstanceService();
var subscriptionService = svcManager.GetWorkflowSubscriptionService();
var wfs = subscriptionService.EnumerateSubscriptions();
web.Context.Load(subscriptionService);
web.Context.Load(wfInstancesManager);
web.Context.Load(wfs);
web.Context.ExecuteQuery();
WorkflowSubscription parentSubscription = null;
foreach (var wf in wfs)
{
if (wf.Name == wfSubscriptionName)
{
parentSubscription = wf;
break;
}
}
if (parentSubscription != null)
{
var instancesCount = wfInstancesManager.CountInstancesWithStatus(parentSubscription, status);
web.Context.ExecuteQuery();
Console.WriteLine($"There is {instancesCount.Value} of instances with status {status.ToString()} for {parentSubscription.Name} workflow");
}
else
{
Console.WriteLine($"Workflow subscription was not found by name {wfSubscriptionName}");
}
}