0

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!

0

Yes, you have to pass the subscription object. subscriptionService has a method getSubscription, that you can use to get the subscription object directly.

You can find more details in my post here

  • What I was missing was the loading of the context without any parameters, after calling the countInstances function. Your post helped me out there, thanks! – Johannes Apr 28 '17 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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