---
sourceDocument: Xanadu API リファレンス
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ja-JP/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - ja-JP

ft:publication_title :

    - Xanadu API リファレンス

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# フロー - スコープ指定 (非推奨)

# フロー - スコープ指定 (非推奨) {#ariaid-title1}

* リリースバージョン: Xanadu
* 
* 更新日 2024年08月01日
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 所要時間：7分

Flow API はアクティブ化された ワークフロースタジオ フローを実行するメソッドを提供します。

この API は廃止され、 [ScriptableFlowRunner - スコープ指定](https://servicenow-prod.fluidtopics.net/EQbAziSqeaz5keLuv620mA#ScriptableFlowRunnerScopedAPI "フロー、サブフロー、およびアクション実行のパラメーターを定義するために使用するビルダーオブジェクトを作成します。特定のドメインで実行するフローを指定できます。ビルダーから直接フロー、サブフロー、またはアクションの実行を開始し、ScriptableFlowRunnerResult オブジェクトで結果を表示します。") および [ScriptableFlowRunnerResult - スコープ指定](https://servicenow-prod.fluidtopics.net/c8I2bjR6f125De7BnO4UoA#ScriptableFlowRunnerResultScopedAPI "ScriptableFlowRunner を使用してフロー、サブフロー、またはアクションを実行した結果をキャプチャします。コンテキスト ID、ドメイン、フロー実行の出力などのデータが含まれます。")API に置き換えられました。

Flow API はサーバースクリプトでのみ使用できます。

`sn_fd` 名前空間を使用して、Flow API にアクセスします。

Flow API を使用してフローとやり取りする前に、まず ワークフロースタジオ インターフェイスでフローを作成してアクティブ化する必要があります。Flow API は構築済みフローのみとやり取りするため、クラスのコンストラクタはありません。  
注:  
インスタンスのパフォーマンスを最適化するには、非同期ビジネスルールスクリプトからこれらのメソッドを呼び出さないようにします。代わりに、ワークフロースタジオの UI 内でスケジュール済みジョブレコードを作成します。

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

トリガーを無視し、アクティブ化されたフローを非同期に実行します。
非同期呼び出しは非ブロッキングであるため、クライアントは、フローが完了するのを待たずにスクリプト内の他のコードを実行できます。
{#FlowScoped-startAsync_S_GR__table_s1t_yn5_ncb__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| scopeName.flowName | 文字列 | 実行するフローのアプリケーションスコープとフローの内部名。scopeName が含まれていない場合、現在ログインしているユーザーのスコープが使用されます。内部名列 (ワークフロースタジオ ランディングページ上) を使用してフローの内部名を取得します。 |
| flowInputs | マップ | レコードベースのフロー入力を定義する`<String、Object>`フォーマット内のネームバリューペア。 レコードベースのトリガーでフローを呼び出すには、次の形式を使用します。 var flowInputs = {}; flowInputs['current'] = glideRecord; flowInputs['table_name'] = glideRecord.getTableName(); GlideRecord オブジェクトの名前は 「current」でなければなりません。 フローをサービスカタログトリガーと呼び出すには、次の形式を使用します。 var flowInputs = {}; flowInputs['request_item'] = glideRecord; flowInputs['table_name'] = glideRecord.getTableName(); GlideRecordオブジェクトの名前は 「request_item」でなければなりません。 |
[表 : 1. パラメーター]

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

| タイプ | 説明 |
|-|-|
| オブジェクト | 次のプロパティを含む PlanResponse オブジェクト： * contextId：実行されたフローの実行詳細レコードのsys_id。実行の詳細にアクセスするには、フロー実行タブにナビゲートします。 ワークフロースタジオsys_idでフィルターリングします。 {#FlowScoped-startAsync_S_GR__ul_bd2_k2v_ncb} フローが次のときに例外が発生します。 * 指定されたアプリケーションスコープ内に存在しないか、フロー名またはスコープ名のスペルが間違っています。 * 有効化されていません。 * com.glide.hub.flow_engine.indirect_recursion_limit システム プロパティで設定された再帰制限を超えている。デフォルト値は 3です。 {#FlowScoped-startAsync_S_GR__ul_ub3_n3t_pcb} |
[表 : 2. 返される内容]

{#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);
    	}

    })();


