{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":909,"path":"api-reference/server-api-reference/ScriptableFlowAPI.md","title":"FlowAPI - Scoped, Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# FlowAPI - Scoped, Global\n\nThe FlowAPI provides methods to execute actions, flows, or subflows in server-side scripts using either blocking or non-blocking methods.\n\nAccess FlowAPI methods in global and scoped scripts using the `sn_fd` namespace. Create calls to your flows using the **Code Snippet** action in Workflow Studio or use the methods detailed here to update scripts manually.\n\n**Note:** In domain separated instances, flows, subflows, and actions triggered by this API run in the domain of the user who started the script. For example, if a user in the Acme domain starts a script that triggers a flow, the flow runs in the Acme domain and can only access Acme data, even if the flow runs as the System User.\n\n**Note:** To optimize instance performance, avoid calling these methods from an asynchronous business rule script. Instead, create a scheduled job record within the Workflow Studio UI.\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## FlowAPI - cancel\\(String contextId, String reason\\)\n\nCancels a paused or running flow, subflow, or action.\n\n<table id=\"table_twb_vmn_p3b\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ncontextId\n\n</td><td>\n\nString\n\n</td><td>\n\nSys\\_id of the execution details record for the flow, subflow, or action. Access the execution details by navigating to the Flow Executions tab in Workflow Studio, or pass the sys\\_id of the context record returned by the startFlow\\(\\), startSubflow\\(\\), or startAction\\(\\) methods.**Note:** There might be a small delay in cancellation if the target context is running on a different node of the instance. Contexts running on the same node are cancelled immediately. Contexts running on another node must first wait for the cancellation to be forwarded to the appropriate node.\n\n</td></tr><tr><td>\n\nreason\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Reason for canceling the flow, subflow, or action. Appears in the **Message** field of the Flow engine log entries \\[sys\\_flow\\_log\\] table.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\nThis example uses the return value of the startFlow\\(\\) method to cancel any long-running flows.\n\n```\n(function() { \n\nvar now_GR = new GlideRecord('incident'); \nnow_GR.addQuery('number', 'INC0000050'); \nnow_GR.query(); \nnow_GR.next(); \n\n      try { \n          var inputs = {}; \n          inputs['current'] = now_GR; // GlideRecord of table: \n          inputs['table_name'] = 'incident'; \n\n          // Starts the flow asynchronously.\n          var result = sn_fd.FlowAPI.getRunner()\n          .flow('global.myFlow')\n          .inBackground()\n          .withInputs(inputs)\n          .run();\n\n          var contextId = result.getContextId();\n          var dateRun = result.getDate();\n          var domainUsed = result.getDomainId();\n          var flowName = result.getFlowObjectName();\n          var flowObjectType = result.getFlowObjectType(); \n\n      } catch (ex) { \n          var message = ex.getMessage(); \n          gs.error(message); \n      } \n})();\n\n \n// Call the cancel() method using the context Id returned from the startFlow() method\nsn_fd.FlowAPI.cancel(contextId, 'Flow took too long to execute.');\n```\n\nThis example cancels any flows named Test Flow.\n\n```\nvar now_GR = new GlideRecord(\"sys_flow_context\");\nnow_GR.addQuery(\"name\", \"Test Flow\");\nnow_GR.query();\n\nwhile (now_GR.next()) {\nsn_fd.FlowAPI.cancel(now_GR.getUniqueValue(), 'Canceling Test Flows');\n} \n```\n\n## FlowAPI - executeAction\\(String name, Map inputs, Number timeout\\)\n\nRuns an action from a server-side script synchronously.\n\nExecute an action from within a business rule, script include, or any other server-side script. Actions run using this method run synchronously, so the method has access to outputs created by the action. Use **startAction** to run an action asynchronously.\n\n**Note:** This API is replaced by [ScriptableFlowRunner - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ScriptableFlowRunnerScopedAPI.md), which deprecates the existing methods used to build objects and execute Workflow Studio flows and actions. Use the getRunner\\(\\) method in the FlowAPI class to return a ScriptableFlowRunner object and use the associated methods. Use the ScriptableFlowRunner methods if you need to support domain separation.\n\n**Note:** This method runs the action as the user who initiates the session.\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|The scope and name of the action to be executed, for example `global.action_name`.|\n|inputs|Map|Name-value pairs that define action inputs. Use the input name, not the input label.|\n|timeout|Number|Optional. Timeout in milliseconds. This value overrides the 30 second default timeout specified by the **com.glide.hub.flow\\_api.default\\_execution\\_time** system property. After the timeout expires, an exception is thrown.|\n\n|Type|Description|\n|----|-----------|\n|Object|The action outputs.|\n\nIn this example, the script uses sn\\_fd.FlowAPI.executeAction to execute an action called actionforpassword2test in the global scope. A variable called inputs contains the inputs for the action. In this case, a name and password. The outputs for the action are stored in the outputs variable, which in this case, is an encrypted password object. The code is wrapped in a try/catch statement to capture any errors that might occur when the flow executes.\n\n```\n(function() {\n\t\n  try {\n    var inputs = {};\n    inputs['name'] = ; // String \n    inputs['password2'] = ; // Password (2 Way Encrypted) \n\t\t\n    // Execute Synchronously: Run in foreground. Code snippet has access to outputs.\n    // var timeout = ; //timeout in ms\n    //sn_fd.FlowAPI.executeAction('global.actionforpassword2test', inputs, timeout)\n    var outputs = sn_fd.FlowAPI.executeAction('global.actionforpassword2test', inputs);\n\n    // Get Outputs:\n    // Note: outputs can only be retrieved when executing synchronously.\n    var output = outputs['output']; // Password (2 Way Encrypted)\n\t\t\n  } catch (ex) {\n    var message = ex.getMessage();\n    gs.error(message);\n  }\n})();\n```\n\n## FlowAPI - executeActionQuick\\(String name, Map inputs, Number timeout\\)\n\nRun an action from a server-side script synchronously from the current user session without creating execution details or other related records. Improve performance by eliminating record-keeping overhead. Use this API to increase the speed of high-volume processing, for example multiple executions per second, in a production environment.\n\n-   **Reporting &amp; records generated**\n\n    This method does not create execution details and context records, regardless of Workflow Studio settings.\n\n-   **Wait support**\n\n    This method does not support pausing the action to wait for conditions. Steps that pause for wait conditions such as Ask for Approval or Wait for Condition are not supported.\n\n-   **MID Server support**\n\n    This method does not support pausing an action to run from a MID Server.\n\n\n**Note:** This API is replaced by [ScriptableFlowRunner - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ScriptableFlowRunnerScopedAPI.md), which deprecates the existing methods used to build objects and execute Workflow Studio flows and actions. Use the getRunner\\(\\) method in the FlowAPI class to return a ScriptableFlowRunner object and use the associated methods. Use the ScriptableFlowRunner methods if you need to support domain separation.\n\n<table id=\"table_gx5_kcf_1hb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nname\n\n</td><td>\n\nString\n\n</td><td>\n\nScope and internal name of the action to execute. For example, `global.action_name`. Locate the **Internal name** field in the list of Workflow Studio actions.\n\n</td></tr><tr><td>\n\ninputs\n\n</td><td>\n\nMap\n\n</td><td>\n\nName-value pairs that define action inputs. You can find the available action inputs and required data types under Inputs in the action outline. Use the input name, not the input label. For example, `{'table':'incident','sys_id':'a39d8e3cf0212300964feeefe80ff0ed'}`.\n\n</td></tr><tr><td>\n\ntimeout\n\n</td><td>\n\nNumber\n\n</td><td>\n\nOptional. Timeout in milliseconds. This value overrides the 30 second default timeout specified by the **com.glide.hub.flow\\_api.default\\_execution\\_time** system property. After the timeout expires, an exception is thrown.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|Object|Object containing outputs defined by the action. You can find the outputs for the action under **Outputs** in the action outline.|\n\n```\n(function() {\n  try {\n\n    var grIncident = new GlideRecord('incident');\n    grIncident.get('57af7aec73d423002728660c4cf6a71c');\n\n    var inputs = {};\n    inputs['variable'] = grIncident;\n\n    var outputs = sn_fd.FlowAPI.executeActionQuick('global.update_record_test', inputs);\n\n    // Get Outputs:\n    // Note: outputs can only be retrieved when executing synchronously.\n    var output1 = outputs['output1']; \n\n  } catch (ex) { \n    var message = ex.getMessage();\n    gs.error(message);\n    }\n\t\n})();\n```\n\n## FlowAPI - executeDataStreamAction\\(String name, Map inputs, Number timeout\\)\n\nRuns a Data Stream action synchronously from a server-side script and returns a ScriptableDataStream object.\n\nFor more information about Data Stream actions, see [Data Stream actions and pagination](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/integrate-applications/data-stream-actions.md).\n\n**Note:** This API is replaced by [ScriptableFlowRunner - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ScriptableFlowRunnerScopedAPI.md), which deprecates the existing methods used to build objects and execute Workflow Studio flows and actions. Use the getRunner\\(\\) method in the FlowAPI class to return a ScriptableFlowRunner object and use the associated methods. Use the ScriptableFlowRunner methods if you need to support domain separation.\n\n**Note:** Always wrap data stream logic in a `try/catch` block to catch errors. Always include a `finally` statement that ends with the close\\(\\) method from the ScriptableDataStream class to close the data stream and prevent performance issues.\n\n<table id=\"table_oz4_hd3_z3b\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nname\n\n</td><td>\n\nString\n\n</td><td>\n\nThe scope and name of the Data Stream action to execute. For example, `global.data_stream_action_name`.\n\n</td></tr><tr><td>\n\ninputs\n\n</td><td>\n\nMap\n\n</td><td>\n\nName-value pairs that define action inputs. Use the input name, not the input label. If the action does not have any inputs, do not include this parameter.\n\n</td></tr><tr><td>\n\ntimeout\n\n</td><td>\n\nNumber\n\n</td><td>\n\nOptional. Amount of time before the action times out. After the timeout expires, an exception is thrown. The timeout only applies to the executeDataStreamAction method, not to methods in the ScriptableDataStream class.Default: 30000, specified by the **com.glide.hub.flow\\_api.default\\_execution\\_time** system property\n\n Unit: Milliseconds\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|ScriptableDataStream|An object used to iterate through items in the data stream. Use the methods in the ScriptableDataStream class to interact with this object. See [ScriptableDataStream API](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ScriptableDataStreamAPI.md).|\n\nThis example creates an incident record for each item returned in the data stream.\n\n```\n(function() {\n\t\n  try {\n\n    // Execute Data Stream Action. \n    var stream = sn_fd.FlowAPI.executeDataStreamAction('x_my_scope.data_stream_name');\n\n    // Process each item in the data stream\n    while (stream.hasNext()) {\n\n      // Get a single item from the data stream.\n      var item = stream.next();\n\n      // Use the item. \n      var now_GR = new GlideRecord('incident');\n      now_GR.setValue('number',item.id);\n      now_GR.setValue('short_description',item.name);\n      now_GR.insert();\n\t\t\n      // By default, this code snippet will terminate after 10 items.\n      // Remove or modify this limit after testing your code.\n      if (stream.getItemIndex() >= 9) {\n        break;\n      }\n    }\n  } catch (ex) {\n    var message = ex.getMessage();\n    gs.error(message);\n  } finally {\n    stream.close();\n  }\n\t\n})();\n```\n\n## FlowAPI - executeFlow\\(String name, Map inputs, Number timeout\\)\n\nRuns a flow from a server-side script synchronously.\n\nExecute a flow from within a business rule, script include, or any other server-side script. Flows run using this method run synchronously. Use **startFlow** to run a flow asynchronously.\n\n**Note:** This API is replaced by [ScriptableFlowRunner - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ScriptableFlowRunnerScopedAPI.md), which deprecates the existing methods used to build objects and execute Workflow Studio flows and actions. Use the getRunner\\(\\) method in the FlowAPI class to return a ScriptableFlowRunner object and use the associated methods. Use the ScriptableFlowRunner methods if you need to support domain separation.\n\n**Note:** This method runs the flow as the user specified in flow properties.\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|The scope and name of the flow to be executed, for example `global.flow_name`.|\n|inputs|Map|Name-value pairs that define trigger inputs. Use the input name, not the input label.|\n|timeout|Number|Optional. Timeout in milliseconds. This value overrides the 30 second default timeout specified by the **com.glide.hub.flow\\_api.default\\_execution\\_time** system property. After the timeout expires, an exception is thrown.|\n\n|Type|Description|\n|----|-----------|\n|None|Normal operation produces no return value.|\n|Exception|The API throws an exception when a flow called synchronously pauses. `The current execution is in the waiting state`. In most cases, the exception is removed when the flow resumes. However, the API cannot resume a flow that has been sent to a MID Server.|\n\nThis example uses sn\\_fd.FlowAPI.executeFlow to execute a global flow called test\\_flow. This flow is normally triggered when a record on the incident table is updated. Because you are activating the flow from a script, you must provide this information. The code creates an inputs variable that contains the current record, and the table for the record. The code is wrapped in a try/catch statement to capture any errors that might occur when the flow executes.\n\n```\n(function() {\n  try {\n    var inputs = {};\n    inputs['current'] = ; // GlideRecord of table:  \n    inputs['table_name'] = 'incident';\n\n    // Execute Synchronously: Run in foreground.\n    // var timeout = ; //timeout in ms\n    //sn_fd.FlowAPI.executeFlow('global.test_flow', inputs, timeout)\n    sn_fd.FlowAPI.executeFlow('global.test_flow', inputs);\n  } catch (ex) {\n    var message = ex.getMessage();\n    gs.error(message);\n  }\n})();\n```\n\n## FlowAPI - executeFlowQuick\\(String name, Map inputs, Number timeout\\)\n\nRuns a flow, subflow, action, or Data Stream action from a server-side script synchronously or asynchronously without creating execution details or other related records. Improves performance by eliminating record-keeping overhead. Use this API to increase the speed of high-volume processing, for example multiple executions per second, in a production environment.\n\n-   **Reporting &amp; records generated**\n\n    This method does not create execution details and context records, regardless of Workflow Studio settings.\n\n-   **Run as user**\n\n    This method runs the flow as the user who initiates the session. Setting the flow to run as the system user, or impersonating a user, is not supported.\n\n-   **Wait support**\n\n    This method does not support pausing the flow to wait for conditions. Actions or flow logic that pause for wait conditions such as Ask for Approval, Wait for Condition, or Wait for a duration are not supported.\n\n-   **MID Server support**\n\n    This method does not support pausing a flow to run from a MID Server.\n\n\n**Note:** This API is replaced by [ScriptableFlowRunner - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ScriptableFlowRunnerScopedAPI.md), which deprecates the existing methods used to build objects and execute Workflow Studio flows and actions. Use the getRunner\\(\\) method in the FlowAPI class to return a ScriptableFlowRunner object and use the associated methods. Use the ScriptableFlowRunner methods if you need to support domain separation.\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|Scope and internal name of the flow to execute. For example, `global.flow_name`. Locate the **Internal name** field in the list of Workflow Studio flows.|\n|inputs|Map|Name-value pairs that define trigger inputs. You can find the available trigger inputs and required data types in the Trigger section of the flow. Use the input name, not the input label. For example, `{'table':'incident','sys_id':'a39d8e3cf0212300964feeefe80ff0ed'}`.|\n|timeout|Number|Optional. Timeout in milliseconds. This value overrides the 30 second default timeout specified by the **com.glide.hub.flow\\_api.default\\_execution\\_time** system property. After the timeout expires, an exception is thrown.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\n(function() {\n\t\n  try {\n    var grIncident = new GlideRecord('incident');\n    grIncident.get('ed92e8d173d023002728660c4cf6a7bc');\n\n    var inputs = {};\n    inputs['current'] = grIncident;\n    inputs['table_name'] = 'incident';\n\t\t\n    sn_fd.FlowAPI.executeFlowQuick('global.test_quick_flow', inputs);\n\t\t\n  } catch (ex) {\n    var message = ex.getMessage();\n    gs.error(message);\n\t}\n\t\n})();\n```\n\n## FlowAPI - executeSubflow\\(String name, Map inputs, Number timeout\\)\n\nRuns an subflow from a server-side script synchronously.\n\nExecute a subflow from within a business rule, script include, or any other server-side script. Subflows run using this method run synchronously. Use **startSubflow** to run an subflow asynchronously.\n\n**Note:** This API is replaced by [ScriptableFlowRunner - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ScriptableFlowRunnerScopedAPI.md), which deprecates the existing methods used to build objects and execute Workflow Studio flows and actions. Use the getRunner\\(\\) method in the FlowAPI class to return a ScriptableFlowRunner object and use the associated methods. Use the ScriptableFlowRunner methods if you need to support domain separation.\n\n**Note:** This method runs the flow as the user specified in flow properties.\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|The scope and name of the subflow to be executed, for example `global.subflow_name`.|\n|inputs|Map|Name-value pairs that define subflow inputs. Use the input name, not the input label.|\n|timeout|Number|Optional. Timeout in milliseconds. This value overrides the 30 second default timeout specified by the **com.glide.hub.flow\\_api.default\\_execution\\_time** system property. After the timeout expires, an exception is thrown.|\n\n|Type|Description|\n|----|-----------|\n|Object|Object containing the subflow outputs.|\n|Exception|The API throws an exception when a flow called synchronously pauses. `The current execution is in the waiting state`. In most cases, the exception is removed when the flow resumes. However, the API cannot resume a flow that has been sent to a MID Server.|\n\nIn this example, the script uses sn\\_fd.FlowAPI.executeSubflow to execute an subflow called subflowTest in the global scope. A variable called inputs contains the inputs for the subflow. In this case, a name and password. The code is wrapped in a try/catch statement to capture any errors that might occur when the flow executes.\n\n```\n\n(function() {\n\t\n\ttry {\n\t\tvar inputs = {};\n\t\tinputs['name'] = ; // String \n\t\tinputs['password2'] = ; // Password (2 Way Encrypted) \n\t\t\n\t\t// Execute Synchronously: Run in foreground.\n\t\t// var timeout = ; //timeout in ms\n              //sn_fd.FlowAPI.executeSubflow('global.subflowTest', inputs, timeout)\n              var outputs = sn_fd.FlowAPI.executeSubflow('global.subflowTest', inputs);\n\t\t\n\t} catch (ex) {\n\t\tvar message = ex.getMessage();\n\t\tgs.error(message);\n\t}\t\n})();\n```\n\n## FlowAPI - executeSubflowQuick\\(String name, Map inputs, Number timeout\\)\n\nRun a subflow from a server-side script synchronously from the current user session without creating execution details or other related records. Improve performance by eliminating record-keeping overhead. Use this API to increase the speed of high-volume processing, for example multiple executions per second, in a production environment.\n\n-   **Reporting &amp; records generated**\n\n    This method does not create execution details and context records, regardless of Workflow Studio settings.\n\n-   **Run as user**\n\n    This method runs the flow as the user who initiates the session. Setting the flow to run as the system user, or impersonating a user, is not supported.\n\n-   **Wait support**\n\n    This method does not support pausing the flow to wait for conditions. Actions or flow logic that pause for wait conditions such as Ask for Approval, Wait for Condition, or Wait for a duration are not supported.\n\n-   **MID Server support**\n\n    This method does not support pausing a flow to run from a MID Server.\n\n\n**Note:** This API is replaced by [ScriptableFlowRunner - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ScriptableFlowRunnerScopedAPI.md), which deprecates the existing methods used to build objects and execute Workflow Studio flows and actions. Use the getRunner\\(\\) method in the FlowAPI class to return a ScriptableFlowRunner object and use the associated methods. Use the ScriptableFlowRunner methods if you need to support domain separation.\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|Scope and internal name of the subflow to execute. For example, `global.subflow_name`. Locate the **Internal name** field in the list of Workflow Studio subflows.|\n|inputs|Map|Name-value pairs that define subflow inputs. You can find the available subflow inputs and required data types under Inputs in the subflow. Use the input name, not the input label. For example, `{'table':'incident','sys_id':'a39d8e3cf0212300964feeefe80ff0ed'}`.|\n|timeout|Number|Optional. Timeout in milliseconds. This value overrides the 30 second default timeout specified by the **com.glide.hub.flow\\_api.default\\_execution\\_time** system property. After the timeout expires, an exception is thrown.|\n\n|Type|Description|\n|----|-----------|\n|Object|Object containing outputs defined by the subflow. You can find the outputs for the subflow under **Subflow Inputs &amp; Outputs** in the subflow outline.|\n\n```\n(function() {\n\n  try {\n    var grIncident = new GlideRecord('incident');\n    grIncident.get('57af7aec73d423002728660c4cf6a71c');\n\n    var inputs = {};\n    inputs['variable'] = grIncident;\n\n    var outputs = sn_fd.FlowAPI.executeSubflowQuick('global.test_quick_run_subflow', inputs);\n\n    // Get Outputs:\n    // Note: outputs can only be retrieved when executing synchronously.\n    var output1 = outputs['output1']; \n\t\t\n  } catch (ex) {\n    var message = ex.getMessage();\n    gs.error(message);\n    }\n\t\n})();\n```\n\n## FlowAPI - getErrorMessage\\(String contextId\\)\n\nReturns the error messages produced by a flow, subflow, or action. This method cannot return messages from flows, subflows, or actions run with the quick\\(\\) API.\n\n|Name|Type|Description|\n|----|----|-----------|\n|contextId|String|The sys\\_id of the flow, subflow, or action whose error messages you want to get.|\n\n|Type|Description|\n|----|-----------|\n|String|The last operation run and the error message it produced.|\n\nThis example starts a global subflow called test\\_error\\_subflow and returns any error messages it produces. Normally, a single script does not both run a flow and then get its error messages. Typically, either another script or Workflow Studio would have already run the flow. The code is wrapped in a try/catch statement to capture any errors that might occur when the flow executes.\n\n```\n(function() {\n\n  try {\n    // Gather inputs to call flow\n    var inputs = {};\n    inputs['ah_task'] = myTaskRecord; // GlideRecord of table: task\n    inputs['ah_comment'] ='Test Comment' ; // String\n\n    // Call flow with known errors\n    var contextId = sn_fd.FlowAPI.startSubflow('global.test_error_subflow', inputs);\n\n    // Get flow error message\n    var errormsg = sn_fd.FlowAPI.getErrorMessage(contextId);\n    return errormsg;\n\n  } catch (ex) {\n    var message = ex.getMessage();\n    gs.error(message);\n  }\n})();\n\n```\n\nOutput:\n\n```\nOperation (test_error_flow.574033f6db6811102166e2291396199f.274073f6db6811102166e22913961908.0be0d916c31332002841b63b12d3ae13) failed with error: com.snc.process_flow.exception.OpException: Value of field record is not a GlideRecord\nat com.snc.process_flow.operation.FieldValue.getGlideRecord(FieldValue.java:145)\nat com.snc.process_flow.operation.CRUDOperation.getInputValidGlideRecord(CRUDOperation.java:54)\nat com.snc.process_flow.operation.RecordDeleteOperation.run(RecordDeleteOperation.java:26)\nat com.snc.process_flow.engine.Operation.execute(Operation.java:212)\nat com.snc.process_flow.engine.restricted_caller_access.ExecuteWithCallerAccessTracking.executeWithMetaStack(ExecuteWithCallerAccessTracking.java:31)\nat com.snc.process_flow.engine.ProcessEngine.executeOps(ProcessEngine.java:570)\nat com.snc.process_flow.engine.ProcessEngine.runInternal(ProcessEngine.java:476)\nat com.snc.process_flow.engine.ProcessEngine.run(ProcessEngine.java:462)\nat com.snc.process_flow.engine.ProcessAutomation.run(ProcessAutomation.java:86)\nat com.snc.process_flow.engine.GlideProcessAutomation.runSync(GlideProcessAutomation.java:155)\nat com.snc.process_flow.engine.GlideProcessAutomation.runWithDomain(GlideProcessAutomation.java:270)\nat com.snc.process_flow.engine.GlideProcessAutomation.lambda$runAsUserSync$1(GlideProcessAutomation.java:237)\nat com.snc.process_flow.engine.PFSessionClone.run(PFSessionClone.java:70)\nat com.snc.process_flow.engine.GlidePFSession.runPlanAsUserSession(GlidePFSession.java:42)\nat com.snc.process_flow.engine.GlideProcessAutomation.runAsUserSync(GlideProcessAutomation.java:235)\nat com.snc.process_flow.engine.GlideProcessAutomation.messageFlow(GlideProcessAutomation.java:330)\nat com.snc.process_flow.engine.GlideProcessAutomation.messageFlow(GlideProcessAutomation.java:309)\nat com.snc.process_flow.engine.ProcessHubEventHandler.doSendMessage(ProcessHubEventHandler.java:475)\nat com.snc.process_flow.engine.ProcessHubEventHandler.process(ProcessHubEventHandler.java:119)\nat com.snc.process_flow.engine.ProcessHubEventHandler.process(ProcessHubEventHandler.java:91)\nat com.snc.process_flow.engine.FlowEventManager.processEvents(FlowEventManager.java:122)\nat com.glide.job.EventHandlerJob.execute(EventHandlerJob.java:38)\nat com.glide.schedule.JobExecutor.lambda$executeJob$0(JobExecutor.java:129)\nat com.snc.db.data_replicate.replicator.DataReplicationAdvisors.runInOriginatorContext(DataReplicationAdvisors.java:73)\nat com.glide.schedule.JobExecutor.lambda$inDataReplicationContext$2(JobExecutor.java:159)\nat com.glide.schedule.JobExecutor.executeJob(JobExecutor.java:132)\nat com.glide.schedule.JobExecutor.execute(JobExecutor.java:116)\nat com.glide.schedule_v2.SchedulerWorkerThread.executeJob(SchedulerWorkerThread.java:338)\nat com.glide.schedule_v2.SchedulerWorkerThread.lambda$process$0(SchedulerWorkerThread.java:220)\nat com.glide.worker.TransactionalWorkerThread.executeInTransaction(TransactionalWorkerThread.java:35)\nat com.glide.schedule_v2.SchedulerWorkerThread.process(SchedulerWorkerThread.java:220)\nat com.glide.schedule_v2.SchedulerWorkerThread.run(SchedulerWorkerThread.java:101)\n```\n\n## FlowAPI - getFlowStages\\(String scopedFlowName\\)\n\nReturn a JSON string containing the list of flow stages.\n\n|Name|Type|Description|\n|----|----|-----------|\n|scopedFlowName|String|The application scope and name of the flow whose stages you want to get.|\n\n|Type|Description|\n|----|-----------|\n|String|JSON formatted string that lists the stages of the flow by their stage record values.|\n\nThis example shows getting the stages for the Service Catalog Item Request flow.\n\n```\n(function() {\n\n  try {\n    // Name of flow with stages\n    var flowName = \"service_catalog_item_request\";\n\n    // Get flow stages\n    var flowStages = sn_fd.FlowAPI.getFlowStages(flowName);\n    //Print JSON as info message  \n    gs.info(flowStages);\n    return flowStages;\n\n  } catch (ex) {\n    var message = ex.getMessage();\n    gs.error(message);\n  }\n})();\n\n```\n\nOutput:\n\nThe JSON string contains name-value pairs for a stage field. See for more information.\n\n```\n[\n  {\n    \"label\": \"Manager Approval\",\n    \"value\": \"manager_approval\",\n    \"type\": \"standard\",\n    \"duration\": \"1970-01-03 00:00:00\",\n    \"states\": {\n      \"pending\": \"Pending - has not started\",\n      \"inprogress\": \"In progress\",\n      \"skipped\": \"Skipped\",\n      \"complete\": \"Completed\",\n      \"error\": \"Error\"\n    },\n    \"flow\": \"30f3d26187e92300e0ef0cf888cb0b91\",\n    \"alwaysShow\": true,\n    \"order\": 0\n  },\n  {\n    \"label\": \"Set current stage state to:  [Error]\",\n    \"value\": \"Set current stage state to:  [Error]\",\n    \"type\": \"error\",\n    \"duration\": \"1970-01-01 00:00:00\",\n    \"states\": {\n      \"pending\": \"Pending - has not started\",\n      \"inprogress\": \"In progress\",\n      \"skipped\": \"Skipped\",\n      \"complete\": \"Completed\",\n      \"error\": \"Error\"\n    },\n    \"flow\": \"30f3d26187e92300e0ef0cf888cb0b91\",\n    \"alwaysShow\": false,\n    \"order\": 0\n  },\n  {\n    \"label\": \"Dept. Head Approval\",\n    \"value\": \"Dept. Head Approval\",\n    \"type\": \"standard\",\n    \"duration\": \"1970-01-03 00:00:00\",\n    \"states\": {\n      \"pending\": \"Pending - has not started\",\n      \"inprogress\": \"In progress\",\n      \"skipped\": \"Skipped\",\n      \"complete\": \"Completed\",\n      \"error\": \"Error\"\n    },\n    \"flow\": \"30f3d26187e92300e0ef0cf888cb0b91\",\n    \"alwaysShow\": true,\n    \"order\": 1\n  },\n  {\n    \"label\": \"CIO Approval\",\n    \"value\": \"CIO Approval\",\n    \"type\": \"standard\",\n    \"duration\": \"1970-01-03 00:00:00\",\n    \"states\": {\n      \"pending\": \"Pending - has not started\",\n      \"inprogress\": \"In progress\",\n      \"skipped\": \"Skipped\",\n      \"complete\": \"Completed\",\n      \"error\": \"Error\"\n    },\n    \"flow\": \"30f3d26187e92300e0ef0cf888cb0b91\",\n    \"alwaysShow\": true,\n    \"order\": 2\n  },\n  {\n    \"label\": \"Order Fulfillment\",\n    \"value\": \"Order Fulfillment\",\n    \"type\": \"standard\",\n    \"duration\": \"1970-01-05 00:00:00\",\n    \"states\": {\n      \"pending\": \"Pending - has not started\",\n      \"inprogress\": \"In progress\",\n      \"skipped\": \"Skipped\",\n      \"complete\": \"Completed\",\n      \"error\": \"Error\"\n    },\n    \"flow\": \"30f3d26187e92300e0ef0cf888cb0b91\",\n    \"alwaysShow\": true,\n    \"order\": 3\n  },\n  {\n    \"label\": \"Backordered\",\n    \"value\": \"Backordered\",\n    \"type\": \"standard\",\n    \"duration\": \"1970-01-15 00:00:00\",\n    \"states\": {\n      \"pending\": \"Pending - has not started\",\n      \"inprogress\": \"In progress\",\n      \"skipped\": \"Skipped\",\n      \"complete\": \"Completed\",\n      \"error\": \"Error\"\n    },\n    \"flow\": \"30f3d26187e92300e0ef0cf888cb0b91\",\n    \"alwaysShow\": true,\n    \"order\": 4\n  },\n  {\n    \"label\": \"Deployment\",\n    \"value\": \"Deployment\",\n    \"type\": \"standard\",\n    \"duration\": \"1970-01-02 00:00:00\",\n    \"states\": {\n      \"pending\": \"Pending - has not started\",\n      \"inprogress\": \"In progress\",\n      \"skipped\": \"Skipped\",\n      \"complete\": \"Completed\",\n      \"error\": \"Error\"\n    },\n    \"flow\": \"30f3d26187e92300e0ef0cf888cb0b91\",\n    \"alwaysShow\": true,\n    \"order\": 5\n  },\n  {\n    \"label\": \"Request Cancelled\",\n    \"value\": \"Request Cancelled\",\n    \"type\": \"standard\",\n    \"duration\": \"1970-01-01 00:00:00\",\n    \"states\": {\n      \"pending\": \"Pending - has not started\",\n      \"inprogress\": \"In progress\",\n      \"skipped\": \"Skipped\",\n      \"complete\": \"Completed\",\n      \"error\": \"Error\"\n    },\n    \"flow\": \"30f3d26187e92300e0ef0cf888cb0b91\",\n    \"alwaysShow\": true,\n    \"order\": 6\n  },\n  {\n    \"label\": \"Completed\",\n    \"value\": \"complete\",\n    \"type\": \"standard\",\n    \"duration\": \"1970-01-01 00:00:00\",\n    \"states\": {\n      \"pending\": \"Pending - has not started\",\n      \"inprogress\": \"In progress\",\n      \"skipped\": \"Skipped\",\n      \"complete\": \"Completed\",\n      \"error\": \"Error\"\n    },\n    \"flow\": \"30f3d26187e92300e0ef0cf888cb0b91\",\n    \"alwaysShow\": true,\n    \"order\": 7\n  }\n]\n```\n\n## FlowAPI - getOutputs\\(String contextId\\)\n\nReturns the outputs of a completed action or subflow.\n\nYou can use the return values from either the startAction\\(\\) orstartSubflow\\(\\) methods as the contextId parameter.\n\n**Note:** This API is replaced by [ScriptableFlowRunner - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ScriptableFlowRunnerScopedAPI.md), which deprecates the existing methods used to build objects and execute Workflow Studio flows and actions. Use the getRunner\\(\\) method in the FlowAPI class to return a ScriptableFlowRunner object and use the associated methods. Use the ScriptableFlowRunner methods if you need to support domain separation.\n\n|Name|Type|Description|\n|----|----|-----------|\n|contextId|String|The sys\\_id of the action or subflow whose outputs you want to get.|\n\n|Type|Description|\n|----|-----------|\n|Object|Object containing the action or subflow outputs.|\n\nThis example starts a global subflow called test\\_subflow, waits for the flow to finish, and then gets its output values. Normally, a single script does not both run a flow and then get its output values. Since a flow may not complete before the getOutputs\\(\\) call, this example uses a wait time. Typically, either another script or Workflow Studio would have already run the flow. The code is wrapped in a try/catch statement to capture any errors that might occur when the flow executes.\n\n```\n(function() {\n\n  try {\n    // Gather inputs to call flow\n    var inputs = {};\n    inputs['ah_task'] = myTaskRecord; // GlideRecord of table: task\n    inputs['ah_comment'] ='Test Comment' ; // String\n\n    // Call flow\n    var contextId = sn_fd.FlowAPI.startSubflow('global.test_subflow', inputs);\n\n    // Wait for the flow to finish running\n\n    // Get flow outputs\n    var outputs = sn_fd.FlowAPI.getOutputs(contextId);\n    var output1 = outputs['output1'];\n    return output1;\n\n  } catch (ex) {\n    var message = ex.getMessage();\n    gs.error(message);\n  }\n})();\n\n```\n\n## FlowAPI - getRunner\\(\\)\n\nReturns a ScriptableFlowRunner builder object for a flow or action that you want to run.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|[ScriptableFlowRunner](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ScriptableFlowRunnerScopedAPI.md)|Builder object used to run a Workflow Studio action, flow, or subflow.|\n\nThis example runs a flow synchronously.\n\n```\n\n(function() {\n  try {\n\n    var inputs = {}; \n\n    inputs['sys_id'] = '57af7aec73d423002728660c4cf6a71c';  // Pass the record's sys_id in as input.  \n\n    var result = sn_fd.FlowAPI.getRunner()  // Create a ScriptableFlowRunner builder object.\n      .action('global.markapproved')        // Run the global scope action named markapproved.\n      .inForeground()\n      .inDomain('TOP/ACME')                 // Run the action from the TOP/ACME domain.                               \n      .withInputs(inputs)\n      .run();                               // Run the action and return a FlowRunnerResult object.\n\n    var contextId = result.getContextId();  // Retrieve the context ID from the result\n    var dateRun = result.getDate();\n    var domainUsed = result.getDomainId();  // Retrieve the Domain ID from the result.\n    var flowName = result.getFlowObjectName();\n    var flowObjectType = result.getFlowObjectType();\n\n    var outputs = result.getOutputs();            // Retrieve any outputs from the action execution.\n    var newApprovalStatus = outputs['approval'];  // Echo back the approval status for verification.\n\t\t\n  } catch (ex) {\n    var message = ex.getMessage();\n    gs.error(message);\n  }\n\t\n})();\n   \n```\n\n## FlowAPI - getStatus\\(String contextId\\)\n\nReturns the status of a flow, subflow, or action.\n\n|Name|Type|Description|\n|----|----|-----------|\n|contextId|String|The sys\\_id of the flow, subflow, or action whose status you want to get.|\n\n<table id=\"table_jsj_glz_dbc\" class=\"returns\"><thead><tr><th>\n\nParameter\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\n&lt;Object&gt;\n\n</td><td>\n\nObject\n\n</td><td>\n\nObject containing the current state of the flow, subflow, or action as name-value pairs. ```\n{\n    \"hasLookupError\": Boolean,\n    \"errorMessage\": \"String\",\n    \"contextStatus\": {Object}\n  }\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.hasLookupError\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether there was an issue looking up the context status of the flow, subflow, or action.```\n{\n    \"hasLookupError\": false,\n    \"errorMessage\": \"\",\n    \"contextStatus\": {Object}\n  }\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.errorMessage\n\n</td><td>\n\nString\n\n</td><td>\n\nError message returned by context lookup operation. This parameter is void when **hasLookupError** is false.```\n{\n    \"hasLookupError\": false,\n    \"errorMessage\": \"\",\n    \"contextStatus\": {Object}\n  }\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.contextStatus\n\n</td><td>\n\nObject\n\n</td><td>\n\nObject containing state details about the queried flow, subflow, or action.```\n{\n    \"hasLookupError\": false,\n    \"errorMessage\": \"\",\n    \"contextStatus\": {\n      \"state\": \"COMPLETE\",\n      \"errorState\": \"NONE\"\n    }\n  }\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.contextStatus.state\n\n</td><td>\n\nString\n\n</td><td>\n\nState of the flow, subflow, or action context. Some state values provide additional information in related parameters.-   COMPLETE provides additional information in the **errorState** parameter\n-   ERROR provides additional information in the **message** parameter\n-   CANCELLED provides additional information in the **canceledReason** parameter\n-   IN\\_PROGRESS provides additional information in the **isRunOnMid** parameter\n-   WAITING provides additional information in the **waitingOn** parameter\n\n```\n{\n    \"hasLookupError\": false,\n    \"errorMessage\": \"\",\n    \"contextStatus\": {\n      \"state\": \"COMPLETE\",\n      \"errorState\": \"NONE\"\n    }\n  }\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.contextStatus.errorState\n\n</td><td>\n\nString\n\n</td><td>\n\nFlow complete state produced by flow error handling. The API only generates this parameter when the flow, subflow, or action is in the COMPLETE state.-   ERROR\\_CAUGHT\n-   ERROR\\_SKIPPED\n\n```\n{\n    \"hasLookupError\": false,\n    \"errorMessage\": \"\",\n    \"contextStatus\": {\n      \"state\": \"COMPLETE\",\n      \"errorState\": \"ERROR_CAUGHT\"\n    }\n  }\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.contextStatus.message\n\n</td><td>\n\nString\n\n</td><td>\n\nError message returned by the flow, subflow, or action. The API only generates this parameter when the flow, subflow, or action is in the ERROR state.```\n{\n    \"hasLookupError\": false,\n    \"errorMessage\": \"\",\n    \"contextStatus\": {\n      \"state\": \"ERROR\",\n      \"message\": \"Error:  Error Message! (Process Automation.LOG; line 1)\"\n    }\n  }\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.contextStatus.canceledReason\n\n</td><td>\n\nString\n\n</td><td>\n\nCancel message returned by the flow, subflow, or action. The API only generates this parameter when the flow, subflow, or action is in the CANCELLED state.```\n{\n    \"hasLookupError\": false,\n    \"errorMessage\": \"\",\n    \"contextStatus\": {\n      \"state\": \"CANCELLED\",\n      \"canceledReason\": \"User has requested to stop executing the flow\"\n    }\n  }\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.contextStatus.isRunOnMid\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the flow, subflow, or action is run on a MID Server environment. The API only generates this parameter when the flow, subflow, or action is in the IN\\_PROGRESS state.```\n{\n    \"hasLookupError\": false,\n    \"errorMessage\": \"\",\n    \"contextStatus\": {\n      \"state\": \"IN_PROGRESS\",\n      \"isRunOnMid\": true\n    }\n  }\n  }\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.contextStatus.waitingOn\n\n</td><td>\n\nArray\n\n</td><td>\n\nList of items that the current flow, subflow, or action is waiting on. The API only generates this parameter when the flow, subflow, or action is in the WAITING state.```\n{\n    \"hasLookupError\": false,\n    \"errorMessage\": \"\",\n    \"contextStatus\": {\n      \"state\": \"WAITING\",\n      \"waitingOn\": [\n        {\n          \"order\":\"1\",\n          \"stepType\": \"TIMER\",\n          \"endTime\": 1713627497643\n        },\n        {\n          \"order\":\"5\",\n          \"stepType\": \"WAIT_FOR_CONDITION_WITH_TIMEOUT\",\n          \"table\": \"incident\",\n          \"condition\": \"sys_id=10e8b43243200210338774d6ebb8f22d^short_description=112\",\n          \"endTime\": 1713645497800\n        }\n      ]\n    }\n  }\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.contextStatus.waitingOn.order\n\n</td><td>\n\nString\n\n</td><td>\n\nFlow step number of the item that is causing the flow to wait. If the waiting action is a custom action within a flow, the order also includes a period and the action step number of custom action on which the flow is waiting.```\n{\n    \"hasLookupError\": false,\n    \"errorMessage\": \"\",\n    \"contextStatus\": {\n      \"state\": \"WAITING\",\n      \"waitingOn\": [\n        {\n          \"order\":\"1\",\n          \"stepType\": \"TIMER\",\n          \"endTime\": 1713627497643\n        },\n        {\n          \"order\":\"5\",\n          \"stepType\": \"WAIT_FOR_CONDITION_WITH_TIMEOUT\",\n          \"table\": \"incident\",\n          \"condition\": \"sys_id=10e8b43243200210338774d6ebb8f22d^short_description=112\",\n          \"endTime\": 1713645497800\n        }\n      ]\n    }\n  }\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.contextStatus.waitingOn.stepType\n\n</td><td>\n\nString\n\n</td><td>\n\nType of action or flow step that is causing the flow, subflow, or action to wait. The API only generates this parameter when the flow, subflow, or action is in the WAITING state. Here are some common examples.-   WAIT\\_FOR\\_CONDITION\n-   WAIT\\_FOR\\_CONDITION\\_WITH\\_TIMEOUT\n-   ASK\\_FOR\\_APPROVAL\n-   CREATE\\_TASK\\_WITH\\_WAIT\n-   TIMER\n-   SLA\\_TIMER\n-   SUBFLOW\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.contextStatus.waitingOn.table\n\n</td><td>\n\nString\n\n</td><td>\n\nTable name containing the record that the flow, subflow, or action is waiting on. The API only generates this parameter when the flow, subflow, or action is in the WAITING state and the stepType is WAIT\\_FOR\\_CONDITION, WAIT\\_FOR\\_CONDITION\\_WITH\\_TIMEOUT, ASK\\_FOR\\_APPROVAL, or CREATE\\_TASK\\_WITH\\_WAIT.```\n{\n    \"hasLookupError\": false,\n    \"errorMessage\": \"\",\n    \"contextStatus\": {\n      \"state\": \"WAITING\",\n      \"waitingOn\": [\n          {\n          \"order\":\"1\",\n          \"stepType\": \"WAIT_FOR_CONDITION\",\n          \"table\": \"incident\",\n          \"condition\": \"sys_id=1347723243200210338774d6ebb8f285^short_description=1238\"\n          }\n        ]\n    }\n  }\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.contextStatus.waitingOn.condition\n\n</td><td>\n\nString\n\n</td><td>\n\nQuery condition of the record that the flow, subflow, or action is waiting on. The API only generates this parameter when the flow, subflow, or action is in the WAITING state and there is a condition that must be met to continue running.```\n{\n    \"hasLookupError\": false,\n    \"errorMessage\": \"\",\n    \"contextStatus\": {\n      \"state\": \"WAITING\",\n      \"waitingOn\": [\n          {\n          \"order\":\"1\",\n          \"stepType\": \"WAIT_FOR_CONDITION\",\n          \"table\": \"incident\",\n          \"condition\": \"sys_id=1347723243200210338774d6ebb8f285^short_description=1238\"\n          }\n        ]\n    }\n  }\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.contextStatus.waitingOn.endTime\n\n</td><td>\n\nInteger\n\n</td><td>\n\nEnd time that the flow, subflow, or action is waiting on. The API only generates this parameter when the flow, subflow, or action is in the WAITING state and the stepType is WAIT\\_FOR\\_CONDITION\\_WITH\\_TIMEOUT, TIMER, or SLA\\_TIMER.```\n{\n    \"hasLookupError\": false,\n    \"errorMessage\": \"\",\n    \"contextStatus\": {\n    \"state\": \"WAITING\",\n    \"waitingOn\": [\n        {\n          \"order\":\"3\",\n          \"stepType\": \"SLA_TIMER\",\n          \"endTime\": 1713574610000\n        }\n    ]\n    }\n  }\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.contextStatus.waitingOn.approvalRule\n\n</td><td>\n\nString\n\n</td><td>\n\nApproval rule that the flow, subflow, or action is waiting on. The API only generates this parameter when the flow, subflow, or action is in the WAITING state and the stepType is ASK\\_FOR\\_APPROVAL.```\n{\n    \"hasLookupError\": false,\n    \"errorMessage\": \"\",\n    \"contextStatus\": {\n      \"state\": \"WAITING\",\n      \"waitingOn\": [\n        {\n          \"order\":\"3\",\n          \"stepType\": \"ASK_FOR_APPROVAL\",\n          \"table\": \"incident\",\n          \"condition\": \"sys_id=3bd89703372002103387963174924b20^approvalINapproved,rejected,cancelled\",\n          \"approvalRule\": \"ApprovesAnyU[a8f98bb0eb32010045e1a5115206fe3a,71826bf03710200044e0bfc8bcbe5d3b]\"\n        }\n      ]\n    }\n  }\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.contextStatus.waitingOn.contextId\n\n</td><td>\n\nString\n\n</td><td>\n\nThe sys\\_id of the subflow that the flow or subflow is waiting on. The API only generates this parameter when the flow, or subflow is in the WAITING state and the stepType is SUBFLOW.```\n{\n    \"hasLookupError\": false,\n    \"errorMessage\": \"\",\n    \"contextStatus\": {\n    \"state\": \"WAITING\",\n    \"waitingOn\": [\n        {\n          \"order\":\"1\",\n          \"stepType\": \"SUBFLOW\",\n          \"contextId\": \"0f724aabd921021020291a665e07e44a\"\n        }\n      ]\n    }\n  }\n```\n\n</td></tr></tbody>\n</table>This example runs a flow containing Do the following in parallel flow logic. Normally, a single script does not both run a flow and then get its error messages. Typically, either another script or Workflow Studio would have already run the flow.\n\n```\n(function() {\n  try {\n    var result = sn_fd.FlowAPI.getRunner()  // Create a ScriptableFlowRunner builder object.\n      .flow('global.test_do_in_parallel')   // Run the global scope flow named do_in_parallel.\n      .run();                               // Run the flow and return a FlowRunnerResult object.\n\n    var contextId = result.getContextId();  // Retrieve the context ID from the result\n\n    var flowStatus = sn_fd.FlowAPI\n      .getStatus(contextId);                // Retrieve any outputs from the flow execution.\n\n    JSON.stringfy(flowStatus);              // Convert object to string\n    return flowStatus;\n\t\t\n  } catch (ex) {\n    var message = ex.getMessage();\n    gs.error(message);\n  }\n\t\n})();\n```\n\nOutput:\n\n```\n{\n    \"hasLookupError\": false,\n    \"errorMessage\": \"\",\n    \"contextStatus\": {\n      \"state\": \"WAITING\",\n      \"waitingOn\": [\n        {\n          \"order\":\"1\",\n          \"stepType\": \"TIMER\",\n          \"endTime\": 1713627497643\n        },\n        {\n          \"order\":\"5\",\n          \"stepType\": \"WAIT_FOR_CONDITION_WITH_TIMEOUT\",\n          \"table\": \"incident\",\n          \"condition\": \"sys_id=10e8b43243200210338774d6ebb8f22d^short_description=112\",\n          \"endTime\": 1713645497800\n        }\n      ]\n    }\n  }\n```\n\n## FlowAPI - hasApprovals\\(String scopedFlowName\\)\n\nChecks if a flow within a give scope contains any Ask for Approval actions.\n\nThe hasApprovals\\(\\) method determines if a flow within a given scope contains any Ask for Approval actions. This method also checks if any Ask for Approval actions within the flow are nested under If flow logic blocks. For more information, see [Ask for Approval actions](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/build-workflows/ask-approval-flow-designer.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|scopedFlowName|String|Scope and internal name of the flow to execute. For example, `global.flow_name`. Locate the **Internal name** field in the list of Workflow Studio flows.|\n\n<table id=\"table_x1d_dz2_vlb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nReturns one of the following string values:-   ALWAYS: The flow contains an Ask for Approval action that isn't nested within a conditional `If` flow logic block.\n-   CONDITIONALLY: The flow contains an Ask for Approval action that is nested within a conditional `If` flow logic block.\n-   NO: The flow doesn't contain any Ask for Approval actions.\n-   UNKNOWN: There was a compiler error, and the system can't determine whether the flow contains any Ask for Approval actions.\n\n</td></tr></tbody>\n</table>The following example checks if the example\\_flow flow within the global scope contains any Ask for Approval actions and logs the result.\n\n```\n(function() {\n\t\n  try {\n    var result = sn_fd.FlowAPI.hasApprovals('global.example_flow');\n    gs.log('Result: ' + result);\n  }\n\n  catch (ex) {\n    var message = ex.getMessage();\n    gs.error(message);\n  }\n})();\n```\n\n## FlowAPI - restartFlowFromContext\\(String ContextId, Map providedInputs\\)\n\nRestarts a flow, subflow, or action that was run in the background. You can provide new inputs or omit them to reuse the previously provided inputs.\n\n|Name|Type|Description|\n|----|----|-----------|\n|contextId|String|The sys\\_id of the flow, subflow, or action you want to restart. This flow, subflow, or action must have run in background and have an associated sysevent record.|\n|providedInputs|Object|Optional. Map object containing the name-value pairs that define replacement inputs for the flow, subflow, or action. If you omit or provide a null value for this parameter, the flow, subflow, or action runs using the previously provided inputs.|\n\n|Type|Description|\n|----|-----------|\n|ScriptableFlowRunnerResultsScoped|Object containing the execution details of a Workflow Studio action, flow, or subflow.|\n\nRestarts a sample flow that has a record-based trigger on the Incident table. The original flow used sample incident INC0008112 as an input. When the flow restarts it instead uses sample incident INC0008111 as an input.\n\n```\n(function() {\n  try {\n\n    var flowContextID = '4216396ffd7d11107edcf07204c30fd5';     // sys_id of sys_flow_context record\n    var oldIncidentRecord = '552c48888c033300964f4932b03eb092'; // sys_id of INC0008112\n    var newIncidentRecord = 'a83820b58f723300e7e16c7827bdeed2'; // sys_id of INC0008111\n    var inputs = {};\n    var gr = new GlideRecord('incident'); // Create new incident object\n\n    gr.get(newIncidentRecord);            // Get GlideRecord object for INC0008111\n\n    inputs['current'] = gr;               // Set new Incident record as input\n    inputs['table_name'] = 'incident';    // Set table name to Incident\n\n    var result = sn_fd.FlowAPI.getRunner()            // Create a ScriptableFlowRunner builder object.\n      .restartFlowFromContext(flowContextID, inputs); // Restart flow with new inputs.\n\n    var contextId = result.getContextId();  // Retrieve the context ID from the result\n    var dateRun = result.getDate();\n\n    gs.info(contextId + ' ' + dateRun);\n\n  } catch (ex) {\n    var message = ex.getMessage();\n    gs.error(message);\n  }\n\n})();\n\n```\n\n## FlowAPI - scheduleCancel\\(String contextId, String reason, Integer delaySeconds\\)\n\nSchedule a system event in the Flow Engine Queue to cancel a flow that is in the in progress, presumed interrupted, or waiting state after a delay.\n\n<table id=\"table_mrg_gpn_v5b\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ncontextId\n\n</td><td>\n\nString\n\n</td><td>\n\nSys\\_id of the execution details record for the flow, subflow, or action. The target flow, subflow, or action must be in the in progress, presumed interrupted, or waiting state. Access the execution details by navigating to the Flow Executions tab in Workflow Studio, or pass the sys\\_id of the context record returned by the method.**Note:** There might be a small delay in cancellation if the target context is running on a different node of the instance. Contexts running on the same node are cancelled immediately. Contexts running on another node must first wait for the cancellation to be forwarded to the appropriate node.\n\n</td></tr><tr><td>\n\nreason\n\n</td><td>\n\nString\n\n</td><td>\n\nReason for canceling the flow, subflow, or action. Appears in the **Message** field of the Flow engine log entries \\[sys\\_flow\\_log\\] table.\n\n</td></tr><tr><td>\n\ndelaySeconds\n\n</td><td>\n\nInteger\n\n</td><td>\n\nOptional. Number of seconds to wait before processing a cancellation event in the Flow Engine Queue. If you omit this parameter, the method uses the default value of 1 second.You can use this parameter to avoid the performance impact of scheduling the cancellation of thousands of flow contexts at the same time. Rather than run all cancellations simultaneously, schedule a batch of flow cancellations with a delay. Alternatively, you could use the delay as a time out value for an asynchronous flow.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\nThis example uses the return value of the startFlow\\(\\) method to schedule the cancellation of any long-running flows.\n\n```\n(function() { \n\nvar now_GR = new GlideRecord('incident'); \nnow_GR.addQuery('number', 'INC0000050'); \nnow_GR.query(); \nnow_GR.next(); \n\n      try { \n          var inputs = {}; \n          inputs['current'] = now_GR; // GlideRecord of table: \n          inputs['table_name'] = 'incident'; \n\n          // Starts the flow asynchronously.\n          var contextId = sn_fd.FlowAPI.startFlow('global.myFlow', inputs); \n\n      } catch (ex) { \n          var message = ex.getMessage(); \n          gs.error(message); \n      } \n})();\n\n \n// Call the scheduleCancel() method using the context Id returned from the startFlow() method\nsn_fd.FlowAPI.scheduleCancel(contextId, 'Flow took too long to execute.', 60);\n```\n\nThis example schedules the cancellation of any flows named Test Flow.\n\n```\nvar now_GR = new GlideRecord(\"sys_flow_context\");\nnow_GR.addQuery(\"name\", \"Test Flow\");\nnow_GR.query();\n\nwhile (now_GR.next()) {\nsn_fd.FlowAPI.scheduleCancel(now_GR.getUniqueValue(), 'Canceling Test Flows', 60);\n} \n```\n\nThis example uses the delaySeconds parameter to run flow cancellation jobs in batches. Use batches to cancel thousands of flow contexts.\n\n```\nvar delaySeconds = 1;\n\nfor (var i; i < sys_flow_context.length; ++i) {\n  if (i % 100 === 0) {\n    delaySeconds = delaySeconds + 60;\n  }\n  var contextId = sys_flow_context[i];\n  var reason = \"Example reason\";\n  sn_fd.FlowAPI.scheduleCancel(contextId, reason, delaySeconds);\n}\n```\n\n## FlowAPI - sendMessage\\(String contextSysID, String message, String payload\\)\n\nSend a specific message and payload response to a flow that is paused and waiting for a message.\n\n|Name|Type|Description|\n|----|----|-----------|\n|contextSysID|String|The sys\\_id value of the flow or subflow that is paused and waiting for a specific message to resume. The flow or subflow must include a Wait for Message action. See [Wait For Message action](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/build-workflows/wait-for-message-action.md).|\n|message|String|The text string to send to the waiting flow or subflow. If this message value matches the message value listed in the Wait for Message action, then the flow or subflow resumes running. See [Wait For Message action](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/build-workflows/wait-for-message-action.md).|\n|payload|String|The text string output value to send to the waiting flow. The flow or subflow can use the payload as an input when it resumes running. For example, you could specify a reason why a record was reopened or that a new approval was required.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis example sends the message `Resume Flow` to restart a paused flow. The paused flow can then use the payload value as data elsewhere in the flow.\n\n```\n(function() {\n    try {\n      // var change = '154a6320db9b12102166e229139619fc';    // Example sys_id of change record\n      var pausedFlowId = '6e9bab60949b1210dda11cd237cd955d'; // Example sys_id of a paused flow\n      var resumeMessage = 'Resume Flow';                     // Message that paused flow is waiting for\n      var payload = 'Resubmitted for approval';              // Data to send back to flow\n      var result = sn_fd.FlowAPI\n      .sendMessage(pausedFlowId, resumeMessage, payload);    // Send a message to the paused flow\n    } catch (ex) {\n      var message = ex.getMessage();\n      gs.error(message);\n    }\n  })();  \n  \n```\n\nOutput:\n\nThis script doesn't produce any output of its own. When you run it from the **Scripts-Background** module, the system lists the operations and tables modified by the script. You can also see the results of the script output in the flow execution details of a Wait for Message action.\n\n```\n[0:00:00.074] Script completed in scope global: script\nScript execution history and recovery available here\nOperation\tTable\t                       Row Count\ndelete\t   sys_flow_runtime_state_chunk\t1\ninsert\t   sys_flow_runtime_state_chunk\t1\nupdate\t   sys_flow_context\t            1\nrecord-watcher asynchronous tracking complete - time: 3 ms. Executed responders: 1 \nrecord-watcher asynchronous tracking complete - time: 3 ms. Executed responders: 1 \nrecord-watcher asynchronous tracking complete - time: 3 ms. Executed responders: 1 \n\n```\n\n## FlowAPI - setEncryptedOutput\\(String password\\)\n\nBuilds password2 values inside a script step.\n\nIdentify an encrypted password2 value returned from a GlideRecord, enabling the system to display the value as a masked password rather than an encrypted string.\n\n|Name|Type|Description|\n|----|----|-----------|\n|password|String|Encrypted password2 value.|\n\n|Type|Description|\n|----|-----------|\n|String|Encrypted password2 value, recognised by the engine as a password value.|\n\nThis example returns value of a password2 field from a user record and stores in in a variable. This variable is passed into the setEncryptedOutput method, which is called using sn\\_fd.GlideActionUtil.setEncryptedOutput. The instance recognises the returned value as a password.\n\n```\n(function execute(inputs, outputs) {\n  // ...code...\n  var now_GR = new GlideRecord('sys_user');\n  now_GR.addQuery('first_name' , 'Abel');\n  now_GR.query();\n  now_GR.next();\n  var pwVal = now_GR.getValue('pw2');\n  outputs['usedSetEncrypted'] = sn_fd.GlideActionUtil.setEncryptedOutput(pwVal);\n  outputs['justSetDirectly'] = pwVal;\n})(inputs, outputs);\n```\n\n## FlowAPI - startAction\\(String name, Map inputs\\)\n\nRuns an action from a server-side script asynchronously.\n\nExecute an action from within a business rule, script include, or any other server-side script. Actions run using this method run asynchronously, so scripts using this method do not have access to any outputs created by the action. Use **executeAction** to run an action synchronously and access the outputs it generates.\n\n**Note:** This API is replaced by [ScriptableFlowRunner - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ScriptableFlowRunnerScopedAPI.md), which deprecates the existing methods used to build objects and execute Workflow Studio flows and actions. Use the getRunner\\(\\) method in the FlowAPI class to return a ScriptableFlowRunner object and use the associated methods. Use the ScriptableFlowRunner methods if you need to support domain separation.\n\n**Note:** This method runs the action as the user who initiates the session.\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|The scope and name of the action to be executed, for example `global.action_name`.|\n|inputs|Map|Name-value pairs that define action inputs. Use the input name, not the input label.|\n\n|Type|Description|\n|----|-----------|\n|String|Sys Id of the context record for the action. Access the context record by navigating to the Flow Executions tab in Workflow Studio, selecting a flow execution, and clicking **Open Context Record**.|\n\nThis example uses sn\\_fd.FlowAPI.startAction to execute an action called add\\_comment in the sn\\_itsm\\_spoke scope. The inputs object contains a target record and a comment to add to that record. The code is wrapped in a try/catch statement to capture any errors that might occur when the flow executes.\n\n```\n(function() {\n  try {\n    var inputs = {};\n    inputs['ah_task'] = myTaskRecord; // GlideRecord of table: task \n    inputs['ah_comment'] ='Test Comment' ; // String \n\n    var contextId = sn_fd.FlowAPI.startAction('sn_itsm_spoke.add_comment', inputs);\t\n\t\t\t\n  } catch (ex) {\n    var message = ex.getMessage();\n    gs.error(message);\n  }\n})();\n```\n\n## FlowAPI - startActionQuick\\(String name, Map inputs\\)\n\nRuns an action from a server-side script asynchronously without creating execution details or other related records. Improve performance by eliminating record-keeping overhead. Use this API to increase the speed of high-volume processing, for example multiple executions per second, in a production environment.\n\n-   **Reporting &amp; records generated**\n\n    This method does not create execution details and context records, regardless of Workflow Studio settings.\n\n-   **Wait support**\n\n    This method does not support pausing the action to wait for conditions. Steps that pause for wait conditions such as Ask for Approval or Wait for Condition are not supported.\n\n-   **MID Server support**\n\n    This method does not support pausing an action to run from a MID Server.\n\n\n**Note:** This API is replaced by [ScriptableFlowRunner - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ScriptableFlowRunnerScopedAPI.md), which deprecates the existing methods used to build objects and execute Workflow Studio flows and actions. Use the getRunner\\(\\) method in the FlowAPI class to return a ScriptableFlowRunner object and use the associated methods. Use the ScriptableFlowRunner methods if you need to support domain separation.\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|Scope and internal name of the action to execute. For example, `global.action_name`. Locate the **Internal name** field in the list of Workflow Studio actions.|\n|inputs|Map|Name-value pairs that define action inputs. You can find the available action inputs and required data types under Inputs in the action outline. Use the input name, not the input label. For example, `{'table':'incident','sys_id':'a39d8e3cf0212300964feeefe80ff0ed'}`.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\n(function() {\n\t\n  try {\n    var grIncident = new GlideRecord('incident');\n    grIncident.get('57af7aec73d423002728660c4cf6a71c');\n\n    var inputs = {};\n    inputs['variable'] = grIncident;\n\n    sn_fd.FlowAPI.startActionQuick('global.update_record_test', inputs);\n\n  } catch (ex) {\n    var message = ex.getMessage();\n    gs.error(message);\n    }\n\t\n})();\n```\n\n## FlowAPI - startFlow\\(String name, Map inputs\\)\n\nRuns a flow from a server-side script.\n\nExecute a flow from within a business rule, script include, or any other server-side script. Flows executed with this method run asynchronously.\n\n**Note:** This API is replaced by [ScriptableFlowRunner - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ScriptableFlowRunnerScopedAPI.md), which deprecates the existing methods used to build objects and execute Workflow Studio flows and actions. Use the getRunner\\(\\) method in the FlowAPI class to return a ScriptableFlowRunner object and use the associated methods. Use the ScriptableFlowRunner methods if you need to support domain separation.\n\n**Note:** This method runs the flow as the user specified in flow properties.\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|The scope and name of the flow to be executed, for example `global.flow_name`.|\n|inputs|Map|Name-value pairs that define trigger inputs. Use the input name, not the input label.|\n\n|Type|Description|\n|----|-----------|\n|String|Sys Id of the context record for the flow. Access the context record by navigating to the Flow Executions tab in Workflow Studio, selecting a flow execution, and clicking **Open Context Record**.|\n\nThis example uses sn\\_fd.FlowAPI.startFlow to execute a global flow called test\\_flow. The code creates an inputs variable that contains inputs required by the flow. In this case, the current record and the table for the record. The code is wrapped in a try/catch statement to capture any errors that might occur when the flow executes.\n\n```\n(function() {\n \n  var now_GR = new GlideRecord('incident'); \n  now_GR.addQuery('number', 'INC0009009'); \n  now_GR.query(); \n  now_GR.next();\n\n  try {\n    var inputs = {};\n    inputs['current'] = now_GR; // GlideRecord of table: Incident\n    inputs['table_name'] = 'incident';\n\n    var contextId = sn_fd.FlowAPI.startFlow('global.test_flow', inputs);\t\n\t\n  } catch (ex) {\n    var message = ex.getMessage();\n    gs.error(message);  \n  }\n})();\n```\n\n## FlowAPI - startFlowQuick\\(String name, Map inputs\\)\n\nRuns a flow from a server-side script asynchronously without creating execution details or other related records. Improve performance by eliminating record-keeping overhead. Use this API to increase the speed of high-volume processing, for example multiple executions per second, in a production environment.\n\n-   **Reporting &amp; records generated**\n\n    This method does not create execution details and context records, regardless of Workflow Studio settings.\n\n-   **Run as System user**\n\n    This method runs the flow as the System user. Setting the flow to run as the user who initiates the session, or impersonating a user, is not supported.\n\n-   **Wait support**\n\n    This method does not support pausing the flow to wait for conditions. Actions or flow logic that pause for wait conditions such as Ask for Approval, Wait for Condition, or Wait for a duration are not supported.\n\n-   **MID Server support**\n\n    This method does not support pausing a flow to run from a MID Server.\n\n\n**Note:** This API is replaced by [ScriptableFlowRunner - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ScriptableFlowRunnerScopedAPI.md), which deprecates the existing methods used to build objects and execute Workflow Studio flows and actions. Use the getRunner\\(\\) method in the FlowAPI class to return a ScriptableFlowRunner object and use the associated methods. Use the ScriptableFlowRunner methods if you need to support domain separation.\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|Scope and internal name of the flow to execute. For example, `global.flow_name`. Locate the **Internal name** field in the list of Workflow Studio flows.|\n|inputs|Map|Name-value pairs that define trigger inputs. You can find the available trigger inputs and required data types in the Trigger section of the flow. Use the input name, not the input label. For example, `{'table':'incident','sys_id':'a39d8e3cf0212300964feeefe80ff0ed'}`.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\n(function() {\n\t\n  try {\n    var grIncident = new GlideRecord('incident');\n    grIncident.get('ed92e8d173d023002728660c4cf6a7bc');\n\n    var inputs = {};\n    inputs['current'] = grIncident;\n    inputs['table_name'] = 'incident';\n\t\t\n    sn_fd.FlowAPI.startFlowQuick('global.test_quick_flow', inputs);\n\t\t\n  } catch (ex) {\n    var message = ex.getMessage();\n    gs.error(message);\n\t}\n\t\n})();\n```\n\n## FlowAPI - startSubflow\\(String name, Map input\\)\n\nRuns a subflow from a server-side script.\n\nExecute a subflow from within a business rule, script include, or any other server-side script. Subflows run using this method run asynchronously Scripts that include this method do not have access to outputs created by the flow. Use **executeSubflow** to run a subflow synchronously and access the outputs it generates.\n\n**Note:** This API is replaced by [ScriptableFlowRunner - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ScriptableFlowRunnerScopedAPI.md), which deprecates the existing methods used to build objects and execute Workflow Studio flows and actions. Use the getRunner\\(\\) method in the FlowAPI class to return a ScriptableFlowRunner object and use the associated methods. Use the ScriptableFlowRunner methods if you need to support domain separation.\n\n**Note:** This method runs the flow as the user specified in flow properties.\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|The scope and name of the subflow to be executed, for example `global.subflow_name`.|\n|inputs|Map|Name-value pairs that define subflow inputs. Use the input name, not the input label.|\n\n|Type|Description|\n|----|-----------|\n|String|Sys Id of the context record for the subflow. Access the context record by navigating to the Flow Executions tab in Workflow Studio, selecting a flow execution, and clicking **Open Context Record**.|\n\nThis example uses sn\\_fd.FlowAPI.startSubflow to execute a global flow called test\\_subflow. The code is wrapped in a try/catch statement to capture any errors that might occur when the flow executes.\n\n```\n(function() {\n  try {\n    var inputs = {};\n    inputs['ah_task'] = myTaskRecord; // GlideRecord of table: task \n    inputs['ah_comment'] ='Test Comment' ; // String \n\n    var contextId = sn_fd.FlowAPI.startSubflow('global.test_subflow', inputs);\n\n  } catch (ex) {\n    var message = ex.getMessage();\n    gs.error(message);\n  }\n\t\n})();\n```\n\n## FlowAPI - startSubflowQuick\\(String name, Map inputs\\)\n\nRuns a subflow from a server-side script asynchronously without creating execution details or other related records. Improve performance by eliminating record-keeping overhead. Use this API to increase the speed of high-volume processing, for example multiple executions per second, in a production environment.\n\n-   **Reporting &amp; records generated**\n\n    This method does not create execution details and context records, regardless of Workflow Studio settings.\n\n-   **Run as System user**\n\n    This method runs the flow as the System user. Setting the flow to run as the user who initiates the session, or impersonating a user, is not supported.\n\n-   **Wait support**\n\n    This method does not support pausing the flow to wait for conditions. Actions or flow logic that pause for wait conditions such as Ask for Approval, Wait for Condition, or Wait for a duration are not supported.\n\n-   **MID Server support**\n\n    This method does not support pausing a flow to run from a MID Server.\n\n\n**Note:** This API is replaced by [ScriptableFlowRunner - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ScriptableFlowRunnerScopedAPI.md), which deprecates the existing methods used to build objects and execute Workflow Studio flows and actions. Use the getRunner\\(\\) method in the FlowAPI class to return a ScriptableFlowRunner object and use the associated methods. Use the ScriptableFlowRunner methods if you need to support domain separation.\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|Scope and internal name of the subflow to execute. For example, `global.subflow_name`. Locate the **Internal name** field in the list of Workflow Studio subflows.|\n|inputs|Map|Name-value pairs that define subflow inputs. You can find the available subflow inputs and required data types under Inputs in the subflow. Use the input name, not the input label. For example, `{'table':'incident','sys_id':'a39d8e3cf0212300964feeefe80ff0ed'}`.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\n(function() {\n\n  try {\n    var grIncident = new GlideRecord('incident');\n    grIncident.get('57af7aec73d423002728660c4cf6a71c');\n\n    var inputs = {};\n    inputs['variable'] = grIncident;\n\n    sn_fd.FlowAPI.startSubflowQuick('global.test_quick_run_subflow', inputs);\n\n  } catch (ex) {\n    var message = ex.getMessage();  \n    gs.error(message);\n    }\n\t\n})();\n```\n\n"}}