Script Include WAIT for a workflow context to complete

Katie A
Mega Guru

I have a script include that STARTS a workflow. Next, I need to WAIT for the workflow context to complete to grab a resulting value and then call another function.

How can I programmatically wait for the condition to be true to proceed? Or, how can I set a TIMER and check the condition again until it becomes true? I was thinking of using the wf.getRunningFlows(current) method to achieve this, but I still need a way to either wait for that condition to be true, or to set a timer and check it again.

I saw this article but it will not work because that is a client side script. Sleeps, Delays, or Waits in Client Scripts - ServiceNow Wiki

var wf = new Workflow();

//Get the workflow id

var   wfId = wf.getWorkflowFromName("Global Hostname Check if Taken");

//Start workflow, passing along name : value pair(s) for mapping to variable

//where input_var_name is the name of the variable declared in gear menu

//and input_var_value is whatever that value should be for this execution of

//workflow

    var vars = {"u_hostname": "hostname123"};

var context = wf.startFlow(wfId, current, current.operation, vars);

wf.getRunningFlows(current); // IF there are no running flows proceed otherwise wait and check again after a certain amount of time

1 ACCEPTED SOLUTION

okay well if you are looking for a way to just do like a timer to keep checking try this out Window setInterval() Method or the setTimeout() method. something recursive like this for a check.



var handleTime = 0;


handleTimeCount();


function handleTimeCount(){


handleTime = handleTime + 1;


t = setTimeout("handleTimeCount()",1000);


}


View solution in original post

6 REPLIES 6

Hi Nathan thanks for the suggestion but I do not think that javascript function is supported in a servicenow Script Include.



org.mozilla.javascript.EcmaError: "window" is not defined.


Caused by error in <refname> at line 38



35: return false;


36: }


37: else if (!cxr.hasNext()) {


==> 38: window.setTimeout(IsContextRunning(contextsysid), 1000);


39: return true;


40: }


so I would put that on the client side and have it call a script include to check and see your conditions. if you are trying to not let user submit unless the conditions are met you can make a flag variable to check off of.