0

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}");
        }            
    }

1 Answer 1

0

There is a simple workaround to get the actual runing WF instanceId on an item.

  1. Make a hidden field named: actualWFInstanceId or something.
  2. In the workflow make the first step to write the WFinstaceId into this hidden filed.
  3. if you want to get the WFinstanceId, you can only read it from that hidden field.
  4. you can do the last step in the WF to empty this field, and then you can count running WFs where is this filed not empty.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.