--- title: FlowAPI - Scoped, Global description: The FlowAPI provides methods to execute actions, flows, or subflows in server-side scripts using either blocking or non-blocking methods.Cancels a paused or running flow, subflow, or action.Runs an action from a server-side script synchronously.Run 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.Runs a Data Stream action synchronously from a server-side script and returns a ScriptableDataStream object.Runs a flow from a server-side script synchronously.Runs 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.Runs an subflow from a server-side script synchronously.Run 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.Returns 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.Return a JSON string containing the list of flow stages.Returns the outputs of a completed action or subflow.Returns a ScriptableFlowRunner builder object for a flow or action that you want to run.Returns the status of a flow, subflow, or action.Checks if a flow within a give scope contains any Ask for Approval actions.Restarts 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.Schedule 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.Send a specific message and payload response to a flow that is paused and waiting for a message.Builds password2 values inside a script step.Runs an action from a server-side script asynchronously.Runs 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.Runs a flow from a server-side script.Runs 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.Runs a subflow from a server-side script.Runs 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. locale: en-US canonical_url: https://www.servicenow.com/docs/r/australia/api-reference/server-api-reference/ScriptableFlowAPI.html release: australia product: Server API Reference classification: server-api-reference topic_type: concept last_updated: "2026-03-12" reading_time_minutes: 45 breadcrumb: [Server API reference, API reference, API implementation and reference] --- # FlowAPI - Scoped, Global The FlowAPI provides methods to execute actions, flows, or subflows in server-side scripts using either blocking or non-blocking methods. Access 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. **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. **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. **Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md) ## FlowAPI - cancel\(String contextId, String reason\) Cancels a paused or running flow, subflow, or action.
| Name | Type | Description |
|---|---|---|
| contextId | String | Sys\_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. |
| reason | String | Optional. Reason for canceling the flow, subflow, or action. Appears in the **Message** field of the Flow engine log entries \[sys\_flow\_log\] table. |
| Name | Type | Description |
|---|---|---|
| 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. |
| 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'}`. |
| 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. |
| Name | Type | Description |
|---|---|---|
| name | String | The scope and name of the Data Stream action to execute. For example, `global.data_stream_action_name`. |
| inputs | Map | Name-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. |
| timeout | Number | Optional. 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 Unit: Milliseconds |
| Parameter | Type | Description |
|---|---|---|
| <Object> | Object | Object containing the current state of the flow, subflow, or action as name-value pairs. ``` { "hasLookupError": Boolean, "errorMessage": "String", "contextStatus": {Object} } ``` |
| <Object>.hasLookupError | Boolean | Flag that indicates whether there was an issue looking up the context status of the flow, subflow, or action.``` { "hasLookupError": false, "errorMessage": "", "contextStatus": {Object} } ``` |
| <Object>.errorMessage | String | Error message returned by context lookup operation. This parameter is void when **hasLookupError** is false.``` { "hasLookupError": false, "errorMessage": "", "contextStatus": {Object} } ``` |
| <Object>.contextStatus | Object | Object containing state details about the queried flow, subflow, or action.``` { "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "COMPLETE", "errorState": "NONE" } } ``` |
| <Object>.contextStatus.state | String | State of the flow, subflow, or action context. Some state values provide additional information in related parameters.- COMPLETE provides additional information in the **errorState** parameter - ERROR provides additional information in the **message** parameter - CANCELLED provides additional information in the **canceledReason** parameter - IN\_PROGRESS provides additional information in the **isRunOnMid** parameter - WAITING provides additional information in the **waitingOn** parameter ``` { "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "COMPLETE", "errorState": "NONE" } } ``` |
| <Object>.contextStatus.errorState | String | Flow 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 - ERROR\_SKIPPED ``` { "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "COMPLETE", "errorState": "ERROR_CAUGHT" } } ``` |
| <Object>.contextStatus.message | String | Error 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.``` { "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "ERROR", "message": "Error: Error Message! (Process Automation.LOG; line 1)" } } ``` |
| <Object>.contextStatus.canceledReason | String | Cancel 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.``` { "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "CANCELLED", "canceledReason": "User has requested to stop executing the flow" } } ``` |
| <Object>.contextStatus.isRunOnMid | Boolean | Flag 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.``` { "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "IN_PROGRESS", "isRunOnMid": true } } } ``` |
| <Object>.contextStatus.waitingOn | Array | List 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.``` { "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "WAITING", "waitingOn": [ { "order":"1", "stepType": "TIMER", "endTime": 1713627497643 }, { "order":"5", "stepType": "WAIT_FOR_CONDITION_WITH_TIMEOUT", "table": "incident", "condition": "sys_id=10e8b43243200210338774d6ebb8f22d^short_description=112", "endTime": 1713645497800 } ] } } ``` |
| <Object>.contextStatus.waitingOn.order | String | Flow 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.``` { "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "WAITING", "waitingOn": [ { "order":"1", "stepType": "TIMER", "endTime": 1713627497643 }, { "order":"5", "stepType": "WAIT_FOR_CONDITION_WITH_TIMEOUT", "table": "incident", "condition": "sys_id=10e8b43243200210338774d6ebb8f22d^short_description=112", "endTime": 1713645497800 } ] } } ``` |
| <Object>.contextStatus.waitingOn.stepType | String | Type 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 - WAIT\_FOR\_CONDITION\_WITH\_TIMEOUT - ASK\_FOR\_APPROVAL - CREATE\_TASK\_WITH\_WAIT - TIMER - SLA\_TIMER - SUBFLOW |
| <Object>.contextStatus.waitingOn.table | String | Table 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.``` { "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "WAITING", "waitingOn": [ { "order":"1", "stepType": "WAIT_FOR_CONDITION", "table": "incident", "condition": "sys_id=1347723243200210338774d6ebb8f285^short_description=1238" } ] } } ``` |
| <Object>.contextStatus.waitingOn.condition | String | Query 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.``` { "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "WAITING", "waitingOn": [ { "order":"1", "stepType": "WAIT_FOR_CONDITION", "table": "incident", "condition": "sys_id=1347723243200210338774d6ebb8f285^short_description=1238" } ] } } ``` |
| <Object>.contextStatus.waitingOn.endTime | Integer | End 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.``` { "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "WAITING", "waitingOn": [ { "order":"3", "stepType": "SLA_TIMER", "endTime": 1713574610000 } ] } } ``` |
| <Object>.contextStatus.waitingOn.approvalRule | String | Approval 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.``` { "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "WAITING", "waitingOn": [ { "order":"3", "stepType": "ASK_FOR_APPROVAL", "table": "incident", "condition": "sys_id=3bd89703372002103387963174924b20^approvalINapproved,rejected,cancelled", "approvalRule": "ApprovesAnyU[a8f98bb0eb32010045e1a5115206fe3a,71826bf03710200044e0bfc8bcbe5d3b]" } ] } } ``` |
| <Object>.contextStatus.waitingOn.contextId | String | The 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.``` { "hasLookupError": false, "errorMessage": "", "contextStatus": { "state": "WAITING", "waitingOn": [ { "order":"1", "stepType": "SUBFLOW", "contextId": "0f724aabd921021020291a665e07e44a" } ] } } ``` |
| Type | Description |
|---|---|
| String | Returns 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. - CONDITIONALLY: The flow contains an Ask for Approval action that is nested within a conditional `If` flow logic block. - NO: The flow doesn't contain any Ask for Approval actions. - UNKNOWN: There was a compiler error, and the system can't determine whether the flow contains any Ask for Approval actions. |
| Name | Type | Description |
|---|---|---|
| contextId | String | Sys\_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. |
| reason | String | Reason for canceling the flow, subflow, or action. Appears in the **Message** field of the Flow engine log entries \[sys\_flow\_log\] table. |
| delaySeconds | Integer | Optional. 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. |