Failure retry looping workflow/activities

bennyphipps
Giga Expert

Hi,

We have a SOAP activity that occasionally fails with a Socket Error (lord knows why - it has been raised as a HI).

To try and mitigate this (and could be useful for other workflows) if it fails I would to trigger a timer and retry again after 30 seconds.   However I'd like it to only retry X number of times...

below is the workflow and the script in the "Something we want to run" script.   The first one just creates the variable "workflow.scratchpad.i" which is what I'm using as the counter.

find_real_file.pngfind_real_file.png

gs.log("Number of retries is: " + workflow.scratchpad.i);

answer = getAnswer();

        function getAnswer() {

            if(workflow.scratchpad.i < 2){

                workflow.scratchpad.i++;

                return "no";

}

                  else if (workflow.scratchpad.i > 1){

                return "Yes";

}

}


However the workflow just cancels when it gets to the timer and doesn't wait as I'd expect:

find_real_file.png

Workflow context shows:

find_real_file.png

Any idea what I'm doing wrong???

3 REPLIES 3

russ_sarbora
ServiceNow Employee
ServiceNow Employee

Both transition conditions on the "Something we want to run" activity are passing. In that situation, the engine queues up both the Timer and End. The Timer activity runs, but then gets immediately cancelled because End executes next. Check that Yes condition expression.


Hi,



I changed it for an IF statement and it seems to work a bit better as it will route if through the no condition but when it changes to "Yes" it syill seems to route through to the timer but is then cancelled ("Cancelling workflow - it has exceeded the max activity count of 100")



Script:


find_real_file.png



Then you can see it continues to log the answer as "Yes" but still loops roudn the No loop??



find_real_file.png



Workflow itself:


find_real_file.png


Using the Turnstile activity is alternative approach that requires less scripting. In this flow, the doSomething Run Script looks like this:



activity.scratchpad.doSomething = doSomething();


function doSomething() {


  //return true if something worked, false if it failed


  return false;     //we're always returning false to test the failure exit


}



with conditions for:


activity.scratchpad.doSomething == true


activity.scratchpad.doSomething != true


retry loop.png



Still, something is not quite sitting right with me about your script approach not working. I'll try to reproduce it next.