{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":158,"path":"api-reference/GlideFlowAPI.md","title":"GlideFlow - Client","bundle":null,"doc_type":null,"release":"australia","body":"\n# GlideFlow- Client\n\nThe GlideFlow API provides methods for client-side interactions with actions, flows, and subflows.\n\nYou can use this API with classic ServiceNow AI Platform UI experiences that accept 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.\n\n**Note:** This APi is incompatible with the Workspace Experience UI.\n\nSome 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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) or [AngularJS documentation](https://docs.angularjs.org/api/ng/service/$q).\n\nUsing this API, you can:\n\n-   Start actions, flows, or subflows via a script.\n-   Get an existing execution.\n-   Get the status and any available outputs.\n-   Wait for the completion of an action, flow, or subflow.\n\nThere is no constructor for the GlideFlow API. Access GlideFlow methods using the `GlideFlow` global object.\n\n**Parent Topic:**[Client API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/api-client.md)\n\n## GlideFlow - execution.awaitCompletion\\(\\)\n\nReturns a completion object for the execution.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Object|An object that contains completion details for a flow or action execution.|\n\nIn 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.\n\n```\n\n(function() {\n\tvar inputs = {};\n\n\tinputs['input1'] = 'string input'; // String\n\n\tGlideFlow.startAction('global.action_name', inputs)\n\t\t.then(function(execution) {\n\t\t\treturn execution.awaitCompletion();\n\t\t}, errorResolver)\n\t\t.then(function(completion) {\n\t\t\tvar status = completion.status;\n\t\t\tconsole.log(status);\n\n\t\t\t// Available Outputs:\n\t\t\tvar outputs = completion.outputs;\n\t\t\tconsole.log(outputs);\n\t\t}, errorResolver());\n\n\tfunction errorResolver(error) {\n\t\t// Handle errors in error resolver\n\t\tconsole.error(error);\n\t}\n})();\n```\n\n## GlideFlow - execution.getExecutionStatus\\(\\)\n\nReturns a string containing the execution status of the current execution.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|A string containing the execution status.|\n\nIn 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.\n\n```\n\n// Get an existing action, getStatus, and getOutputs if complete\n(function() {\n   GlideFlow.getExecution('mamIN4Q35vmEFe744EwJV5GHrSz8fmJG')\n      .then(function(execution) {\n         execution.getExecutionStatus().then(\n            function(status) {\n               if (status === 'COMPLETE')\n                  execution.getOutputs().then(\n                     function(outputs) {\n                        console.log(outputs);\n                     },\n                     errorResolver\n                  );\n            },\n            errorResolver\n         );\n      }, errorResolver);\n\n   function errorResolver(error) {\n      // Handle errors in error resolver\n      console.error(error);\n   }\n})();\n```\n\n## GlideFlow - execution.getOutputs\\(\\)\n\nReturns an outputs object for the execution.\n\nUse this method to access output generated by the execution of an action, flow, or subflow.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Object|An object containing outputs for an action, flow, or subflow.|\n\nIn 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.\n\n```\n\n// Get an existing action, getStatus, and getOutputs if complete\n(function() {\n   GlideFlow.getExecution('mamIN4Q35vmEFe744EwJV5GHrSz8fmJG')\n      .then(function(execution) {\n         execution.getExecutionStatus().then(\n            function(status) {\n               if (status === 'COMPLETE')\n                  execution.getOutputs().then(\n                     function(outputs) {\n                        console.log(outputs);\n                     },\n                     errorResolver\n                  );\n            },\n            errorResolver\n         );\n      }, errorResolver);\n\n   function errorResolver(error) {\n      // Handle errors in error resolver\n      console.error(error);\n   }\n})();\n```\n\n## GlideFlow - getExecution\\(String executionId\\)\n\nGet an existing execution instance by ID.\n\n|Name|Type|Description|\n|----|----|-----------|\n|executionId|String|The ID of the execution to be retrieved.|\n\n|Type|Description|\n|----|-----------|\n|Object|A promise of an execution object.|\n\nIn 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.\n\n```\n\n// Get an existing action and await completion\n(function() {\n\tGlideFlow.getExecution('79cd437e0b202300a150a95e93673ae3')\n\t\t.then(function(execution) {\n\t\t\treturn execution.awaitCompletion();\n\t\t}, errorResolver)\n\t\t.then(function(completion) {\n\n\t\t\tvar status = completion.status;\n\t\t\tconsole.log(status);\n\n\t\t\t// Available Outputs:\n\t\t\tvar outputs = completion.outputs;\n\t\t\tconsole.log(outputs);\n\t\t}, errorResolver());\n\n\tfunction errorResolver(error) {\n\t\t// Handle errors in error resolver\n\t\tconsole.error(error);\n\t}\n})();\n```\n\n## GlideFlow - startAction\\(String scopedName.actionName, Map inputs\\)\n\nStart an action.\n\n|Name|Type|Description|\n|----|----|-----------|\n|scopedName|String|The scoped name of the flow to be executed.|\n|inputs|Object|An object containing inputs defined for the action.|\n\n|Type|Description|\n|----|-----------|\n|Object|An object containing details on the action execution.|\n\nIn 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.\n\n```\n\n// Start an action and await completion.\n(function() {\n\tvar inputs = {};\n\n\tinputs['input1'] = 'string input'; // String\n\n\tGlideFlow.startAction('global.action_name', inputs)\n\t\t.then(function(execution) {\n\t\t\treturn execution.awaitCompletion();\n\t\t}, errorResolver)\n\t\t.then(function(completion) {\n\t\t\tvar status = completion.status;\n\t\t\tconsole.log(status);\n\n\t\t\t// Available Outputs:\n\t\t\tvar outputs = completion.outputs;\n\t\t\tconsole.log(outputs);\n\t\t}, errorResolver());\n\n\tfunction errorResolver(error) {\n\t\t// Handle errors in error resolver\n\t\tconsole.error(error);\n\t}\n})();\n```\n\n## GlideFlow - startFlow\\(String scopedName.flowName, Map inputs\\)\n\nStart a flow.\n\n|Name|Type|Description|\n|----|----|-----------|\n|scopedName|String|The scoped name of the flow to be executed.|\n|inputs|Object|An object containing inputs defined for the flow.|\n\n|Type|Description|\n|----|-----------|\n|Object|An object containing details on the flow execution.|\n\nThis 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\n\n```\n\n// Start a Flow\n(function() {\n      var inputs = {};\n      inputs['current'] = { // GlideRecord \n        table : 'incident', \n        sys_id : '79cd437e0b202300a150a95e93673ae3'  \n    };\n        inputs['table_name'] = 'incident';\n         GlideFlow.startFlow('global.flow_name', inputs)\n\t\t.then(\n\t\t\tfunction(execution) {\n\t\t\t\tconsole.log('Started flow_name with execution id :' + execution.getExecutionId());\n\t\t\t},\n\t\t\tfunction(error) {\n\t\t\t\tconsole.log('Unable to start flow: ' + error);\n\t\t\t}\n\t\t);\n})();\n```\n\n## GlideFlow - startSubflow\\(String scopedName.subflowName, Map inputs\\)\n\nStart a subflow.\n\n|Name|Type|Description|\n|----|----|-----------|\n|scopedName|String|The scoped name of the flow to be executed.|\n|inputs|Object|An object containing inputs used for the subflow.|\n\n|Type|Description|\n|----|-----------|\n|Object|An object containing details on the subflow execution.|\n\nIn 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.\n\n```\n\n// Start an action and await completion.\n(function() {\n\tvar inputs = {};\n\n\tinputs['input1'] = 'string input'; // String\n\n\tGlideFlow.startSubflow('global.subflow_name', inputs)\n\t\t.then(function(execution) {\n\t\t\treturn execution.awaitCompletion();\n\t\t}, errorResolver)\n\t\t.then(function(completion) {\n\t\t\tvar status = completion.status;\n\t\t\tconsole.log(status);\n\n\t\t\t// Available Outputs:\n\t\t\tvar outputs = completion.outputs;\n\t\t\tconsole.log(outputs);\n\t\t}, errorResolver());\n\n\tfunction errorResolver(error) {\n\t\t// Handle errors in error resolver\n\t\tconsole.error(error);\n\t}\n})();\n```\n\n"}}