I'm trying to get a count of all instances of a workflow by status. Below is the code I'm using. I have not been able to find a lot of information about WorkflowInstanceService.CountInstancesWithStatus from googling. The only thing I was able to find was this blop post.
All I'm setting with this is an empty response. Any help with this is appreciated. Thanks.
function GetWorkflowStatus(subscriptionId, wfCountCellID){
var siteUrl = _spPageContextInfo.webAbsoluteUrl;
var context = SP.ClientContext.get_current();
var workflowServicesManager = SP.WorkflowServices.WorkflowServicesManager.newObject(context, context.get_web());
var workflowSubscriptionService = workflowServicesManager.getWorkflowSubscriptionService();
var workflowInstanceService = workflowServicesManager.getWorkflowInstanceService();
var subscription = workflowSubscriptionService.getSubscription(subscriptionId);
context.load(subscription);
var stats = [1,4,5,6];
execute(context).then(function() {
stats.forEach(function (st){
var wfResp = workflowInstanceService.countInstancesWithStatus(subscription, st);
var count = wfResp.get_value();
execute(context).done(function() {
document.getElementById(wfCountCellID + st).textContent = count;
}).fail(function(message) {
console.error(message);
});
});
});
};