
- 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 07:22 PM
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: }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2016 05:56 AM
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.