
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2016 02:20 PM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2016 03:39 PM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2016 02:28 PM
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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2016 02:31 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2016 03:39 PM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2016 03:46 PM
you would then just put your conditions in to get out of the recursion.