I am trying to query all the workflows with a specific state ('started') from a list with javascript (or the first one, since only one workflow "can" be running).
Using the InstanceService I can query all the instances (including 'completed') of workflows in the list, but querying those requires a lot of time (for 100 items). I tried getting all the WorkflowSubscriptions (which worked fine), and then using the CountInstancesWithStatus
method (see msdn). I pass the subscription into the function, and already tried the numeric and the textual values for the status, but it always returns an empty SP.Result
-object. I also tried (as shown in the code sample below) CountInstances
that doesn't need a status to be passed in.
I'm assuming the the subscription
returned from the the SubscriptionService
is the parentSubscription
needed by the function. I found no other way of retrieving a subscription
.
var servicesManager = SP.WorkflowServices.WorkflowServicesManager.newObject(context, web)
var instanceService = servicesManager.getWorkflowInstanceService()
var subscriptionService = servicesManager.getWorkflowSubscriptionService()
var deploymentService = servicesManager.getWorkflowDeploymentService()
// ...
var subs = subscriptionService.enumerateSubscriptionsByList(listId)
context.load(subs)
context.executeQueryAsync(() => {
var enumerator = subs.getEnumerator()
while (enumerator.moveNext()) {
var sub = enumerator.get_current()
var instances = instanceService.countInstances(sub) // empty SP.Result
}
)
I did not find any further information regarding the method or this behaviour. Any help would be greatly appreciated!