0
SPList list = web.Lists.GetList(new Guid(listGuid), false);
SPListItem item = list.GetItemById(int.Parse(listItemId));
string currentStatus = item["Status"].ToString();
if (currentStatus == "Pending Approval")
{
    SPWorkflowCollection workflows = item.Workflows;
    // Do more stuff
}

Why does item.Workflows ALWAYS return nothing, even though I know there is a workflow running for this item.

I'm also sure I have the correct SPListItem object; the currentStatus condition confirms this.

I found these two questions that are related, but refer to SPListItem.Tasks rather than SPListItem.Workflows (perhaps they're related):

SPListItem.Tasks always empty
SPWorkflow.Tasks is empty when not in debug

2
  • Please make sure you are referring to the correct list with which the workflow is associated not to the task list of the worklow.
    – Avijit Sur
    Jan 5, 2015 at 15:41
  • Avjit, as I mentioned, I'm sure I am referring to the correct list as I have the correct item in item
    – Submits
    Jan 5, 2015 at 15:47

1 Answer 1

2

I am not sure why it's returning an empty collection.

In 2013 you can enumerate instances using following code:

Reference Microsoft.SharePoint.WorkflowServicesBase.dll

WorkflowServicesManager workflowServiceManager = new WorkflowServicesManager(web);
var workflowInstanceService = workflowServiceManager.GetWorkflowInstanceService();
var workflowInstances = workflowInstanceService.EnumerateInstancesForListItem(listGuid, listItemId);
foreach (var instance in workflowInstances)
{
    //Do Stuff
}
1
  • Amal, thanks for your answer. In the end I went a different route to solve the problem and didn't have to use SPListItem.Workflows. Though I didn't get to try your suggestion, I have a feeling it was a safer route to go, so I'll mark it as the answer.
    – Submits
    Jan 9, 2015 at 11:25

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.