How to Unstick a Workflow Stuck at a Switch Statement

jmiskey
Kilo Sage

A while back, I had an issue with a complex workflow that would occassionally get "stuck" (the old thread can be seen here: https://community.servicenow.com/community?id=community_question&sys_id=86c85396dbbbab044819fb243996...).

In a nutshell, we have a Catalog Item that when completed, will cycle through a few of the variables to create separate RITMs (one for each one of the multi-select fields).  So, it just makes copies of all the other original fields in creating the new RITMs, and then each RITM has its own Workflow.  The issue I was having was a Switch action near the beginning of my workflow, seemed to sometimes try to run before all the variables were copied over.  So the workflow would get "stuck" there. 

In that other ticket, we thought we fixed it by adding a "Wait for Condition", that waited for that Variable used in the Switch statement to be populated.  But it still does not seem to be working consistently.  For example, we had a request that spun off 8 new RITMs.  One worked correctly, the other 7 got "stuck".  I tried re-submitting the same request in our Test system, and 5 worked and 3 got "stuck".  So there is nothing wrong with the code in the Switch statement (as all 8 have the same value).  It seems to be a timing thing (the workflow step trying run before all the variables are being populated).

I am going to continue to play around with it to see if we can get the workflow working properly, but what I really want to know is if there is some way to "unstick" the workflow for these active requests, to get it to proceed to the next step in the workflow, so they can be worked to completion?  The Switch statement should have all the information it needs now, as the variables are all populated.

Otherwise, we need to tell people to cancel and re-submit the requests (which I would prefer not to do!)

Thanks

1 ACCEPTED SOLUTION

So we finally figured out a way to make it work.  We needed to create a UI Action to reset the workflow.  That code looks like this:

var comment = 'Workflow has been reset';

new WorkflowApprovalUtils().cancelAll(current, comment);
new Workflow().restartWorkflow(current);
current.state = '1';
current.update();

The only caveat is it only works if there is a change to the "State" field.  So, if the State field is already '1' to start, we needed to manually change it to something else, save it, and then run this UI Action.

Using this, I was unable to "unstick" all the stuck workflows.

 

Michael,

Though your suggestions did not work, I thank you for your replies.  I learned a lot from them, especially on debugging stuck workflows.

 

View solution in original post

8 REPLIES 8

Michael Fry1
Kilo Patron

Go to  Active Context module under workflow app. Find the stuck working in Executing state and open up the record. There should be a button that says Nudge that will move it past that stage.

I was really hopeful, but unfortunately, that did not do anything.

The RITM shows the field as being populated:

find_real_file.png

But the workflow is still stuck at the Switch statement:

find_real_file.png

Any other ideas?

Note: I know the issue is not with the values in my Switch, as I have other RITMs in the same request that also have chosen this "Modify an existing Role" option that worked fine.

Do I need to delete any of the:

- Workflow Activity History

- Workflow Transition History

- Workflow Log

in order to try to get it to re-process those past steps, or is it dangerous/not advised to mess with those things?

Why is the activity in Blue indicating it finished and not Green for running? If you hover over the activity, does it say anything?

That is a very good question.  I don't know why it claims it finished, but didn't move on, unless it couldn't find a value at that precise moment, and "Finished" and got stuck.

Here is what it looks like when I hover over it:

find_real_file.png