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

Nate23
Mega Guru

in the workflow try putting a scripting activity and call the script include to run from there? or just skip that script include and put it straight into the activity?


Hi Nathan, Unfortunately this all needs to be done within the Script Include. I am using the script include to validate a user input, BEFORE they submit the form.



Here are other posts with the requirements.



Passing a value from a script to use in a workflow



Run Workflow from Client Script then retrieve value BACK before submit


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);


}


you would then just put your conditions in to get out of the recursion.