cancel
Showing results for 
Search instead for 
Did you mean: 

Find the workflows that are failing on items

vacoder
Nintex Newbie
3 7 2,473

In my environment we are using host named site collections for a service that we offer to our clients. Each client has their own site collection and for security and data isolation we use dedicated content databases for both the SP and the Nintex databases. Occasionally a workflow or two will start acting wonky (usually after we upgrade our 3rd party software that we use Nintex to interact with). With over 160 clients you can imagine that it can be more than a couple having trouble and while we do get notified when workflows fail, sometimes a failing workflow is elusive. That's where PowerShell comes in. It may be possible to do this via CSOM but I've not experimented with that much. Using CSOM would let you write a script on your desktop and run it against your farm. It really depends on your permissions.

The trick to finding these workflows is looking at the workflows that are running on an item. Workflows in our environment run against SPItems though we also have a few that run on SPSites. 

After getting a reference to the spWeb and spList of your choice it's just a matter of looping through each item and inspecting each workflow, looking for the info you're after. The ParentAssociation.Name is the name of the workflow that you're looking at. In the example below I am looking for all previous versions on an item and writing them to a log if their state is Running, Faulting, Terminated. You can find your workflow names on the List under "Workflow Settings." in the ribbon. You can find internal states here.

foreach ($item in $list.Items) {
  foreach ($wf in $item.Workflows) {
    if($wf.ParentAssociation.Name -like "*Previous Version*"){
     if($wf.InternalState -match 'Running, Faulting, Terminated'){
     $counter++;

     write-output $item.ID "|" $wf.InternalState "|" $wf.ParentAssociation.Name  | Out-File $outfile -Append}
}
}
}

I have attached 2 versions of the script. One is for looking up workflows on a single list in a single site.Since I have vanity URLs I pass the sub domain and the name of the list for it to query. The second one is the farm one that looks at every workflow on every item on every list on every site on every web application in your SharePoint farm. It sounds like it would peg your CPU and chew up your RAM but its not bad. Try it on your DEV or QA farm first. 

I hope you find these useful and if you have any recommendations on improving them I'd love to hear them.

7 Comments
Automation Master
Automation Master

This is great information! thank so much for working hard on this and providing a huge tool to the community. Dev forum is a great place for this, but I believe you should also submit this to the

vacoder
Nintex Newbie

HI Andrew,

Glad you liked the script. I attempted to publish it to the Xchange but was unable to select that as the target location. I may not have the necessary credentials yet since I saw that selection but it was greyed out for me.

Cheers

Automation Master
Automation Master

So sorry ‌. ‌, Any idea how to help out Richard to publish this?

Automation Master
Automation Master

‌ may also know how to add this to the Xchange. 

Not applicable

I would assume that if Richard Ruth‌ doesn't know if he has credentials, then he probably doesn't. I'll go ask Eric, assuming that Richard has followed the instructions to register here:  

vacoder
Nintex Newbie

Hi Frank...yeah it had assumed I was already set up to submit ... not sure how I managed to bypass the screen you provided but I am on the right path now. Thanks.

Not applicable

Great. I spoke to Eric and he'll be looking for your app.