com.glide.plan.runners.FlowObjectAPIException: The current execution is in the waiting state

Jamsta1912
Tera Guru

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

10 REPLIES 10

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.