find running workflows for an item

  • 30 November 2016
  • 3 replies
  • 36 views

Badge +3

SharePoint 2013 Enterprise, on premise with Nintex Workflow 2013.

We have a workflow on a list, that sometimes hangs on wait events. Users do not really know that the workflow has stopped, and continue editing the item properties until it is complete. The user does not know that the workflow is completed, and one of the last steps of the workflow is to declare the item as a record.

I need to be able to loop through all the items in the list, find those that are completed (a specific field will have one of two values), and check to see if a specific workflow is either still running (hung waiting for a change that has already occurred) or errored. When I identify an item that meets these conditions, I need to kill the specified workflow if it is running, and declare the item as a record.

Any ideas would be most appreciated.


3 replies

Badge +11

Hi John,

that could get a little difficult but here is my idea doing it via a site workflow:

1. Find completed items

Rather easy. Just use a "Querys List" action and query your list for all item IDs. As a result you will have a collection containing all item IDs of your list items. Afterwards you use a "For each" action to loop through all of these IDs. Inside the loop you place another "Query List" action where you query your list again but filter for the item that has the ID you are currently processing inside your loop. You then check this item for your specific field and see if it is completed.

2. Finding Workflows for that item

This is probably the most difficult part as I do not know any method that returns exactly the information you are looking for. However, in the nintex web service there is a method called "GetWorkflowHistoryForListItem" where you can also filter for a workflow state. So if you just provide the workflow state you want to filter for and see if you get any valid history for this method-call it could give you a hint if there is any e. g. errored workflow.

3. Killing the workflow

This should be rather easy again. Just use the "TerminateWorkflowByNameForListItem" method of the nintex web service.

Regards

Philipp

Badge +3

Philipp,

Thanks. I will look into the GetWorkflowHistoryForListItem method. That looks like it will let me filter on both the name and state, which is what I need to do. I think the Query List will let me set a filter on the field to find the items I need, which should significantly limit the size of the collection I need to go through.

Would the Terminate workflow operation work in lieu of the TerminateWorkflowByNameForListItem method?

I was also looking into doing this with PowerShell, and while I could find items with running workflows, I did not have a good way to kill them.

Cheers,

     John

Badge +11

In my suggestion I was talking about a site workflow. Inside a side workflow you will not have the "Terminate Workflow" action available, therefore you have to use the web service in this case. You can only use the "Terminate Workflow" action to terminate a workflow on the item your current workflow is running on.

For terminating a workflow via powershell you can have a look at this thread: Cancel multiple SharePoint Workflows using PowerShell - Stack Overflow

Cheers

Philipp

Reply