Calling subflow in UI Page

John Doe3
ServiceNow Employee
ServiceNow Employee

Hi there,

I am working on a UI Page that calls a subflow in the background. To achieve that, I use the GlideFlow api. While I can confirm that the Subflow was running correctly in the background, I want to achieve these additional features:

  1. The UI Page should wait until the subflow complete, and 
  2. I need the results of the Subflow to be ready before moving on to the next step. 

Currently I have a working prototype similar to this: 

/* some other functions call validateAndSubmit() to begin the process*/

function validateAndSubmit() {

    var promise = new Promise(function(resolve, reject) {
        resolve({
            /* some parameters */
        });
    });

    var executePromise = function() {
        promise.then(function(fulfilled) {
            anotherFunction(fulfilled);
        }).catch(function(error) {
            gs.error(error);
        });
    };

    executePromise();
}


function anotherFunction( /* some parameters */ ) {

    // Some actions ... 

    GlideFlow.startSubflow('name_of_the_subflow', inputs)
        .then(function(execution) {
            return execution.awaitCompletion();
        }, errorResolver)
        .then(function(completion) {
            // I need these returned values 
            var status = completion.status;
            var outputs = completion.outputs;
            xxx = outputs['xxx'];
            yyy = outputs['yyy'];
        });

    function errorResolver(error) {
        // Handle errors in error resolver
    }
}

 

These code doesn't address the two features I want. Can anyone offer any helps and pointers? 

1 REPLY 1

Tom Sienkiewicz
Mega Sage

HI, I guess the second point could be addressed by moving any of your remaining code that needs to run within the completion function.

Perhaps that also solves the first issue. There is no way to trigger flows synchronously from the client that I know of.

There might be another possibility, since UI Pages use Jelly you could try to include a <g:evaluate> Jelly block, and try using server flow api from there, which can run flows synchronously. Never tried that though so not sure if it would work.