The GlideFlow API provides methods for client-side interactions with actions, flows, and subflows.

You can use this API anywhere in the platform that accepts client scripts. The action, flow, or subflow must be set as client callable, and have a valid ACL using the Manage Security feature in Workflow Studio.

Some of the methods within the GlideFlow API return promise objects. A promise represents the eventual result of an asynchronous operation. For more information on promises, see Promise - Javascript MDN or AngularJS documentation.

Using this API, you can:
  • Start actions, flows, or subflows via a script.
  • Get an existing execution.
  • Get the status and any available outputs.
  • Wait for the completion of an action, flow, or subflow.

There is no constructor for the GlideFlow API. Access GlideFlow methods using the GlideFlow global object.

GlideFlow - execution.awaitCompletion()

Returns a completion object for the execution.

Table 1. Parameters
Name Type Description
None
Table 2. Returns
Type Description
Object An object that contains completion details for a flow or action execution.

Example

In this example, an action is executed using startAction(), which returns an execution object. The code then uses awaitCompletion() on this execution object, which returns a completion object. The code uses this completion object to log the status and outputs within the execution.


(function() {
	var inputs = {};

	inputs['input1'] = 'string input'; // String

	GlideFlow.startAction('global.action_name', inputs)
		.then(function(execution) {
			return execution.awaitCompletion();
		}, errorResolver)
		.then(function(completion) {
			var status = completion.status;
			console.log(status);

			// Available Outputs:
			var outputs = completion.outputs;
			console.log(outputs);
		}, errorResolver());

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

GlideFlow - execution.getExecutionStatus()

Returns a string containing the execution status of the current execution.

Table 3. Parameters
Name Type Description
None
Table 4. Returns
Type Description
String A string containing the execution status.

Example

In this example, the code obtains an execution object using the getExecution method. The getExecution method requires an ID, which is returned by the method used to start the execution. The code then uses getExecutionStatus() to determine whether the execution has been completed before continuing.


// Get an existing action, getStatus, and getOutputs if complete
(function() {
   GlideFlow.getExecution('mamIN4Q35vmEFe744EwJV5GHrSz8fmJG')
      .then(function(execution) {
         execution.getExecutionStatus().then(
            function(status) {
               if (status === 'COMPLETE')
                  execution.getOutputs().then(
                     function(outputs) {
                        console.log(outputs);
                     },
                     errorResolver
                  );
            },
            errorResolver
         );
      }, errorResolver);

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

GlideFlow - execution.getOutputs()

Returns an outputs object for the execution.

Use this method to access output generated by the execution of an action, flow, or subflow.

Table 5. Parameters
Name Type Description
None
Table 6. Returns
Type Description
Object An object containing outputs for an action, flow, or subflow.

Example

In this example, the code obtains an execution object using the getExecution method. After the execution is complete, the code uses getOutputs() to return an outputs object, which it then logs using the console.log method.


// Get an existing action, getStatus, and getOutputs if complete
(function() {
   GlideFlow.getExecution('mamIN4Q35vmEFe744EwJV5GHrSz8fmJG')
      .then(function(execution) {
         execution.getExecutionStatus().then(
            function(status) {
               if (status === 'COMPLETE')
                  execution.getOutputs().then(
                     function(outputs) {
                        console.log(outputs);
                     },
                     errorResolver
                  );
            },
            errorResolver
         );
      }, errorResolver);

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

GlideFlow - getExecution(String executionId)

Get an existing execution instance by ID.

Table 7. Parameters
Name Type Description
executionId String The ID of the execution to be retrieved.
Table 8. Returns
Type Description
Object A promise of an execution object.

Example

In this example, the code gets an execution, then waits for it to be completed before logging the executions completion status and outputs using console.log.


// Get an existing action and await completion
(function() {
	GlideFlow.getExecution('79cd437e0b202300a150a95e93673ae3')
		.then(function(execution) {
			return execution.awaitCompletion();
		}, errorResolver)
		.then(function(completion) {

			var status = completion.status;
			console.log(status);

			// Available Outputs:
			var outputs = completion.outputs;
			console.log(outputs);
		}, errorResolver());

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

GlideFlow - startAction(String scopedName.actionName, Map inputs)

Start an action.

Table 9. Parameters
Name Type Description
scopedName String The scoped name of the flow to be executed.
inputs Object An object containing inputs defined for the action.
Table 10. Returns
Type Description
Object An object containing details on the action execution.

Example

In this example, the code starts the global action_name action using arguments in the inputs input object variable. Upon completion, the example uses console.log or console.error to report on the success or failure of the flow.


// Start an action and await completion.
(function() {
	var inputs = {};

	inputs['input1'] = 'string input'; // String

	GlideFlow.startAction('global.action_name', inputs)
		.then(function(execution) {
			return execution.awaitCompletion();
		}, errorResolver)
		.then(function(completion) {
			var status = completion.status;
			console.log(status);

			// Available Outputs:
			var outputs = completion.outputs;
			console.log(outputs);
		}, errorResolver());

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

GlideFlow - startFlow(String scopedName.flowName, Map inputs)

Start a flow.

Table 11. Parameters
Name Type Description
scopedName String The scoped name of the flow to be executed.
inputs Object An object containing inputs defined for the flow.
Table 12. Returns
Type Description
Object An object containing details on the flow execution.

Example

This example flow is normally triggered when a record on the incident table is updated. Because you are activating the flow from Client script, you must provide this information. The code creates an inputs variable that contains the current record and the table for the record


// Start a Flow
(function() {
      var inputs = {};
      inputs['current'] = { // GlideRecord 
        table : 'incident', 
        sys_id : '79cd437e0b202300a150a95e93673ae3'  
    };
        inputs['table_name'] = 'incident';
         GlideFlow.startFlow('global.flow_name', inputs)
		.then(
			function(execution) {
				console.log('Started flow_name with execution id :' + execution.getExecutionId());
			},
			function(error) {
				console.log('Unable to start flow: ' + error);
			}
		);
})();

GlideFlow - startSubflow(String scopedName.subflowName, Map inputs)

Start a subflow.

Table 13. Parameters
Name Type Description
scopedName String The scoped name of the flow to be executed.
inputs Object An object containing inputs used for the subflow.
Table 14. Returns
Type Description
Object An object containing details on the subflow execution.

Example

In this example, the code starts the global subflow_name subflow using arguments in the inputs array variable. Upon completion, the example uses console.log or console.error to report on the success or failure of the flow.


// Start an action and await completion.
(function() {
	var inputs = {};

	inputs['input1'] = 'string input'; // String

	GlideFlow.startSubflow('global.subflow_name', inputs)
		.then(function(execution) {
			return execution.awaitCompletion();
		}, errorResolver)
		.then(function(completion) {
			var status = completion.status;
			console.log(status);

			// Available Outputs:
			var outputs = completion.outputs;
			console.log(outputs);
		}, errorResolver());

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