GlideFlow - Client
The GlideFlow API provides methods for client-side interactions with actions, flows, and subflows.
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.
- 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.
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| Object | An object that contains completion details for a flow or action execution. |
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.
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| String | A string containing the execution status. |
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.
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| Object | An object containing outputs for an action, flow, or subflow. |
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.
| Name | Type | Description |
|---|---|---|
| executionId | String | The ID of the execution to be retrieved. |
| Type | Description |
|---|---|
| Object | A promise of an execution object. |
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.
| Name | Type | Description |
|---|---|---|
| scopedName | String | The scoped name of the flow to be executed. |
| inputs | Object | An object containing inputs defined for the action. |
| Type | Description |
|---|---|
| Object | An object containing details on the action execution. |
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.
| Name | Type | Description |
|---|---|---|
| scopedName | String | The scoped name of the flow to be executed. |
| inputs | Object | An object containing inputs defined for the flow. |
| Type | Description |
|---|---|
| Object | An object containing details on the flow execution. |
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.
| Name | Type | Description |
|---|---|---|
| scopedName | String | The scoped name of the flow to be executed. |
| inputs | Object | An object containing inputs used for the subflow. |
| Type | Description |
|---|---|
| Object | An object containing details on the subflow execution. |
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);
}
})();