How do I get workflow instances for list item on the client side


Badge +1

Hi,

Question: What client side API can I use to retrieve all workflow instances for SharePoint list item?

Environment:
SharePoint 2013/2016 with SharePoint 2010 Workflow platform, i.e. Workflow Manager is NOT installed.
Nintex Workflow

I have the following:
1.    SharePoint site URL
2.    List name
3.    Workflow name
4.    Item ID

I have already tried the following approaches:
1.    WorkflowLog[] NintexWorkflowService.GetWorkflowHistoryForListItem(int itemId, string listName, SPWorkflowState stateFilter, string workflowNameFilter)
http://help.nintex.com/en-US/sdks/sdk2013/Reference/SOAP/NW_REF_SOAP_GetWorkflowHistoryForListItem.htm
This method is not reliable because it may return null even if workflow instance exists.
2.   CSOM WorkflowInstanceService.EnumerateInstancesForListItem(Guid, Int32)
The following C# example does not work:
ClientContext clientContext = new ClientContext(siteUrl);
var workflowServicesManager = new SP.WorkflowServices.WorkflowServicesManager(clientContext, clientContext.Web);
var workflowInstanceService = workflowServicesManager.GetWorkflowInstanceService();
var workflowInstances = workflowInstanceService.EnumerateInstancesForListItem(new Guid("{f79ba745-ffe8-4e77-b3a4-3f37ab7f1b0d}"), 100);
clientContext.Load(workflowInstances);
clientContext.ExecuteQuery();

ExecuteQuery throws an exception: Cannot invoke method or retrieve property from null object. Object returned by the following call stack is null. "GetWorkflowInstanceService
new Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager()"

I will appreciate any help.


2 replies

Userlevel 6
Badge +16

Couldn't you make a SharePoint Query of the list filtering by the status of the workflow?

Badge +1

Hi Fernando, thank you for the reply.

If you mean querying the workflow status column value, how could this help me with getting all workflow instances?

Reply