---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# Flow - Scoped (deprecated)

# Flow - Scoped (deprecated) {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 minutes to read

The Flow API provides methods to run activated Workflow Studio flows.

This API is deprecated and replaced by the [ScriptableFlowRunner - Scoped](https://servicenow-prod.fluidtopics.net/9g_yBasKJW6_Qv4ZGXAFNg#ScriptableFlowRunnerScopedAPI "Creates a builder object used to define parameters for flow, subflow, and action execution. You can specify a flow to execute in a particular domain. Start the flow, subflow, or action execution directly from the builder and view the results in a ScriptableFlowRunnerResult object.") and [ScriptableFlowRunnerResult - Scoped](https://servicenow-prod.fluidtopics.net/2DHowZp00mH_HJe0GOhdUw#ScriptableFlowRunnerResultScopedAPI "Captures the result of using ScriptableFlowRunner to execute a flow, subflow, or action. Includes data such as the context ID, domain, and any outputs from the flow execution.")APIs.

The Flow API can only be used in server scripts.

Use the `sn_fd` namespace to access the Flow API.

Before interacting with a flow using the Flow API, you must first create
and activate the flow in the Workflow Studio interface. Because the
Flow API only interacts with pre-built flows, there is no constructor for
the class.  
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.

## Flow - startAsync(String scopeName.flowName, Map flowInputs) {#ariaid-title2}

Ignores the trigger and runs an activated flow asynchronously.
Asynchronous calls are non-blocking, allowing the client to execute other code in the
script without having to wait for the flow to complete.
{#FlowScoped-startAsync_S_GR__table_s1t_yn5_ncb__entry__3}

| Name | Type | Description |
|-|-|-|
| scopeName.flowName | String | The application scope for the flow and the internal name of the flow to run. If scopeName is not included, the scope of the user currently logged in is used. Retrieve the internal name of the flow using the Internal name column on the Workflow Studio landing page. |
| flowInputs | Map | Name-value pairs in `<String, Object>` format that define record-based flow inputs. To call a flow with a record-based trigger, use the format: var flowInputs = {}; flowInputs['current'] = glideRecord; flowInputs['table_name'] = glideRecord.getTableName(); The GlideRecord object must be named 'current'. To call a flow with a Service Catalog trigger, use the format: var flowInputs = {}; flowInputs['request_item'] = glideRecord; flowInputs['table_name'] = glideRecord.getTableName(); The GlideRecord object must be named 'request_item'. |
[Table 1. Parameters]

{#FlowScoped-startAsync_S_GR__table_s1t_yn5_ncb} {#FlowScoped-startAsync_S_GR__table_t1t_yn5_ncb__entry__2}

| Type | Description |
|-|-|
| Object | PlanResponse object containing the following properties: * contextId: sys_id of the execution details record for the executed flow. Access the execution details by navigating to the Flow Executions tab in Workflow Studio and filtering by sys_id. {#FlowScoped-startAsync_S_GR__ul_bd2_k2v_ncb} An exception occurs when the flow: * Does not exist within the specified application scope, or the flow or scope name has been misspelled. * Is not activated. * Exceeds the recursion limit set by the com.glide.hub.flow_engine.indirect_recursion_limit system property. The default value is three. {#FlowScoped-startAsync_S_GR__ul_ub3_n3t_pcb} |
[Table 2. Returns]

{#FlowScoped-startAsync_S_GR__table_t1t_yn5_ncb}  

    //Example 1: Run a flow with a record-based trigger
    (function startFlowAsync() {

    	try {
    		// You MUST fetch the GlideRecord that will be passed to the flow
    		var glideRecordInput = new GlideRecord('sys_user');
    		glideRecordInput.get('62826bf03710200044e0bfc8bcbe5df1');

    		var flowInputs = {};
    		flowInputs['current'] = glideRecordInput;
    		flowInputs['table_name'] = glideRecordInput.getTableName();

    		var result = sn_fd.Flow.startAsync('global.recordtriggeredflow', flowInputs);

    		//The Sys ID of a flow execution (contextId)
    		var contextId = result.contextId;

    	} catch (ex) {
    		var message = ex.getMessage();
    		gs.error(message);
    	}

    })();

    //Example 2: Run a flow with a schedule-based trigger
    (function startFlowAsync() {

    	try {
    		var result = sn_fd.Flow.startAsync('global.scheduletriggeredflow');

    		//The Sys ID of a flow execution (contextId)
    		var contextId = result.contextId;

    	} catch (ex) {
    		var message = ex.getMessage();
    		gs.error(message);
    	}

    })();

    //Example 3: Run a flow with a Service Catalog trigger
    (function startFlowAsync() {

    	try {
    		// You MUST fetch the GlideRecord that will be passed to the flow
    		var glideRecordInput = new GlideRecord('sc_req_item');
    		glideRecordInput.get(aeed229047801200e0ef563dbb9a71c2);

    		var flowInputs = {};
    		flowInputs['request_item'] = glideRecordInput;
    		flowInputs['table_name'] = glideRecordInput.getTableName();

    		var result = sn_fd.Flow.startAsync('global.catalogtriggeredflow', flowInputs);

    		//The Sys ID of a flow execution (contextId)
    		var contextId = result.contextId;

    	} catch (ex) {
    		var message = ex.getMessage();
    		gs.error(message);
    	}

    })();

    //Example 4: Run a flow with a MetricBase trigger
    (function startMetricBaseFlowAsync() {

    	try {

    		var oilLevelTriggerRecord = new GlideRecord('oil_levels');
    		oilLevelTriggerRecord.get('a4b3622bc72113007b237f48cb97635f');

    		var metricTriggerDefinition = new GlideRecord('sys_metric_trigger_definition');
    		metricTriggerDefinition.get('21f2eae7c72113007b237f48cb976352');

    		var event_time = oilLevelTriggerRecord.getValue('sys_created_on');
    		var level = 4;

    		var metricBaseFlowInputs = {};
    		//The record that triggered the metric event
    		metricBaseFlowInputs['current'] = oilLevelTriggerRecord;
    		//The MetricBase Trigger Definition record
    		metricBaseFlowInputs['metric'] = metricTriggerDefinition;
    		//The time that the 'record' reached a specific metric event level and triggered this flow
    		metricBaseFlowInputs['event_time'] = event_time;
    		//The target event level to reach in order for a metric flow to trigger
    		metricBaseFlowInputs['level'] = level;

    		var result = sn_fd.Flow.startAsync('global.metricbasedtriggeredflow', metricBaseFlowInputs);

    		//The Sys ID of a flow execution (contextId)
    		var contextId = result.contextId;

    	} catch (ex) {
    		var message = ex.getMessage();
    		gs.error(message);
    	}

    })();


