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

Result shows blank. Find the workflow context history, then the Switch and see if you can populate a result. Then try Nudge again. Maybe, maybe it will read the value but no clue.

 

find_real_file.png

I was able to populate it with the correct value, and I hit "Nudge", but it still did not advance.

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.

 

Nice work!