{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":768,"path":"api-reference/server-api-reference/FlowScopedAPI.md","title":"Flow - Scoped \\(deprecated\\)","bundle":null,"doc_type":null,"release":"australia","body":"\n# Flow- Scoped \\(deprecated\\)\n\nThe Flow API provides methods to run activated Workflow Studio flows.\n\nThis API is deprecated and replaced by the [ScriptableFlowRunner - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ScriptableFlowRunnerScopedAPI.md) and [ScriptableFlowRunnerResult - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ScriptableFlowRunnerResultScopedAPI.md)APIs.\n\nThe Flow API can only be used in server scripts.\n\nUse the `sn_fd` namespace to access the Flow API.\n\nBefore 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.\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## Flow - startAsync\\(String scopeName.flowName, Map flowInputs\\)\n\nIgnores the trigger and runs an activated flow asynchronously.\n\nAsynchronous calls are non-blocking, allowing the client to execute other code in the script without having to wait for the flow to complete.\n\n<table id=\"table_s1t_yn5_ncb\" 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\nscopeName.flowName\n\n</td><td>\n\nString\n\n</td><td>\n\nThe 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.\n\n</td></tr><tr><td>\n\nflowInputs\n\n</td><td>\n\nMap\n\n</td><td>\n\nName-value pairs in `<String, Object>` format that define record-based flow inputs.To call a flow with a record-based trigger, use the format:\n\n```\nvar flowInputs = {};\nflowInputs['current'] = glideRecord;\nflowInputs['table_name'] = glideRecord.getTableName();\n```\n\n The GlideRecord object must be named 'current'.\n\n To call a flow with a Service Catalog trigger, use the format:\n\n```\nvar flowInputs = {};\nflowInputs['request_item'] = glideRecord;\nflowInputs['table_name'] = glideRecord.getTableName();\n```\n\n The GlideRecord object must be named 'request\\_item'.\n\n</td></tr></tbody>\n</table><table id=\"table_t1t_yn5_ncb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject\n\n</td><td>\n\nPlanResponse 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.\n\n An exception occurs when the flow:\n\n-   Does not exist within the specified application scope, or the flow or scope name has been misspelled.\n-   Is not activated.\n-   Exceeds the recursion limit set by the **com.glide.hub.flow\\_engine.indirect\\_recursion\\_limit** system property. The default value is three.\n\n</td></tr></tbody>\n</table>```\n//Example 1: Run a flow with a record-based trigger\n(function startFlowAsync() {\n\n\ttry {\n\t\t// You MUST fetch the GlideRecord that will be passed to the flow\n\t\tvar glideRecordInput = new GlideRecord('sys_user');\n\t\tglideRecordInput.get('62826bf03710200044e0bfc8bcbe5df1');\n\n\t\tvar flowInputs = {};\n\t\tflowInputs['current'] = glideRecordInput;\n\t\tflowInputs['table_name'] = glideRecordInput.getTableName();\n\n\t\tvar result = sn_fd.Flow.startAsync('global.recordtriggeredflow', flowInputs);\n\n\t\t//The Sys ID of a flow execution (contextId)\n\t\tvar contextId = result.contextId;\n\n\t} catch (ex) {\n\t\tvar message = ex.getMessage();\n\t\tgs.error(message);\n\t}\n\n})();\n\n//Example 2: Run a flow with a schedule-based trigger\n(function startFlowAsync() {\n\n\ttry {\n\t\tvar result = sn_fd.Flow.startAsync('global.scheduletriggeredflow');\n\n\t\t//The Sys ID of a flow execution (contextId)\n\t\tvar contextId = result.contextId;\n\n\t} catch (ex) {\n\t\tvar message = ex.getMessage();\n\t\tgs.error(message);\n\t}\n\n})();\n\n//Example 3: Run a flow with a Service Catalog trigger\n(function startFlowAsync() {\n\n\ttry {\n\t\t// You MUST fetch the GlideRecord that will be passed to the flow\n\t\tvar glideRecordInput = new GlideRecord('sc_req_item');\n\t\tglideRecordInput.get(aeed229047801200e0ef563dbb9a71c2);\n\n\t\tvar flowInputs = {};\n\t\tflowInputs['request_item'] = glideRecordInput;\n\t\tflowInputs['table_name'] = glideRecordInput.getTableName();\n\n\t\tvar result = sn_fd.Flow.startAsync('global.catalogtriggeredflow', flowInputs);\n\n\t\t//The Sys ID of a flow execution (contextId)\n\t\tvar contextId = result.contextId;\n\n\t} catch (ex) {\n\t\tvar message = ex.getMessage();\n\t\tgs.error(message);\n\t}\n\n})();\n\n//Example 4: Run a flow with a MetricBase trigger\n(function startMetricBaseFlowAsync() {\n\n\ttry {\n\n\t\tvar oilLevelTriggerRecord = new GlideRecord('oil_levels');\n\t\toilLevelTriggerRecord.get('a4b3622bc72113007b237f48cb97635f');\n\n\t\tvar metricTriggerDefinition = new GlideRecord('sys_metric_trigger_definition');\n\t\tmetricTriggerDefinition.get('21f2eae7c72113007b237f48cb976352');\n\n\t\tvar event_time = oilLevelTriggerRecord.getValue('sys_created_on');\n\t\tvar level = 4;\n\n\t\tvar metricBaseFlowInputs = {};\n\t\t//The record that triggered the metric event\n\t\tmetricBaseFlowInputs['current'] = oilLevelTriggerRecord;\n\t\t//The MetricBase Trigger Definition record\n\t\tmetricBaseFlowInputs['metric'] = metricTriggerDefinition;\n\t\t//The time that the 'record' reached a specific metric event level and triggered this flow\n\t\tmetricBaseFlowInputs['event_time'] = event_time;\n\t\t//The target event level to reach in order for a metric flow to trigger\n\t\tmetricBaseFlowInputs['level'] = level;\n\n\t\tvar result = sn_fd.Flow.startAsync('global.metricbasedtriggeredflow', metricBaseFlowInputs);\n\n\t\t//The Sys ID of a flow execution (contextId)\n\t\tvar contextId = result.contextId;\n\n\t} catch (ex) {\n\t\tvar message = ex.getMessage();\n\t\tgs.error(message);\n\t}\n\n})();\n```\n\n"}}