com.glide.plan.runners.FlowObjectAPIException: The current execution is in the waiting state
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2024 09:20 AM
Hello all,
I'm running a script to execute a subflow and make use of the output (actually as part of a function in a scripted REST API). I'm using the standard method to run the subflow synchronously (in the foreground) to wait for the output. Here's a code snippet:
var inputs = {};
inputs['quoteids'] = quoteIds;
var result = sn_fd.FlowAPI.getRunner().subflow('x_canl_circuit_quo.proceed_customer_quote_to_opportunity').inForeground().withInputs(inputs).run();
var outputs = result.getOutputs();
var Orders = outputs['provisioningreqs'] || '';
I can see from the executions that the subflow runs OK. But the issue is, it has a Wait action in it (just for 2 seconds) and I think it's because of that that when I run the script, I get this error:
"com.glide.plan.runners.FlowObjectAPIException: The current execution is in the waiting state"
It's like FlowAPI does not want to wait for any time at all for the Wait action to finish. I guess it just sees the Wait action and then has a little freak out.
Have any of you experienced the same, and know how to deal with it?
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2025 08:50 PM
Yes , i do ..!
Will paste the code snippet here . I assume you can understand that.
Var inputs={} // define ur inputs here
var result = sn_fd.FlowAPI.getRunner()
.subflow('subFlowName')
.inBackground()
.withInputs(inputs)
.run();
var contextId = result.getContextId();
gs.info('Started flow with context ID: ' + contextId);
// Poll sys_flow_context until it completes
var maxWaitMs = 30000; // total max time to wait (30 seconds)
var intervalMs = 2000; // polling interval
var waited = 0;
var contextGr = new GlideRecord('sys_flow_context');
var completed = false;
while (waited < maxWaitMs) {
if (!contextGr.get(contextId)) {
gs.error('Flow context not found: ' + contextId);
return;
}
var state = contextGr.state + ''; // ensure it's a string
gs.info('Flow state: ' + state);
if (state === 'COMPLETE' || state === 'ERROR' || state === 'CANCELLED') {
completed = true;
break;
}
new global.SleepUtils().sleep(intervalMs); // sleep is in ms
waited += intervalMs;
}
if (!completed) {
gs.error('Flow did not complete within timeout.');
return;
}
// Get outputs
var outputs = sn_fd.FlowAPI.getOutputs(contextId);
1. Its a Background SubFlow call.
2. Get the Context ID.
3. Poll the Context Table to get the status.
4. Once status is success or failure, get the results.
