ScriptableDataStream - スコープ付き、グローバル

  • リリースバージョン: Australia
  • 更新日 2026年03月12日
  • 所要時間:12分
  • ScriptableDataStream API は、データのストリームを操作するためのメソッドを提供します。

    このクラスは、次のいずれかの API を使用して ScriptableDataStream オブジェクトを取得した後にのみ、サーバー側スクリプトで使用できます。

    • FlowAPI クラスの executeDataStreamAction() メソッド。「 FlowAPI」を参照してください。
    • ScriptableFlowRunnerResult クラスの getDataStream() メソッド。「 ScriptableFlowRunnerResult」を参照してください。

    ScriptableDataStream オブジェクトを取得した後、次の特定の順序でメソッドを呼び出します。

    1. hasNext() メソッドを使用して、データストリームにさらに項目があるかどうかを判断します。
    2. next() メソッドを使用して、ストリーム内の次のアイテムにアクセスします。
    3. getItemIndex()、getItemInPageIndex()、および getPageIndex() メソッドを使用して、ストリームから情報を取得します。
    4. close() メソッドを使用してストリームを閉じます。

    このクラスの実行は、 sn_fd 名前空間にあります。

    注:
    エラーを捕捉するために、常にデータストリームのロジックを try/catch ブロックで囲みます。データストリームを閉じてパフォーマンスの問題を防ぐために、常に、ScriptableDataStream クラスの close() メソッドで終了する finally ステートメントを含めます。

    ScriptableDataStream:close()

    データストリームへの接続を閉じます。データストリームで必要な操作を実行した後は、必ずこのメソッドを呼び出します。

    このメソッドは、FlowAPI クラスの executeDataStreamAction() メソッドから返された ScriptableDataStream オブジェクトに対してのみ呼び出すことができます。「FlowAPI」を参照してください。

    表 : 1. パラメーター
    名前 タイプ 説明
    なし
    表 : 2. 返される内容
    タイプ 説明
    なし
    (function() {
    	
    	try {
    ​
    		// Execute Data Stream Action. 
    		var stream = sn_fd.FlowAPI.executeDataStreamAction('x_snc_my_scope.data_stream_name');
    ​
    		// Process each item in the data stream
    		while (stream.hasNext()) {
    ​
    			// Get a single item from the data stream.
    			var user = stream.next();
    		
    			// Only log the first item in each page
    			if (stream.getItemInPageIndex() == 0) {
    				gs.info('first user on page is ' + user.name);
    			}
    		}		
    	} catch (ex) {
    		var message = ex.getMessage();
    		gs.error(message);
    	} finally {
    		stream.close();
    	}
    	
    })();

    ScriptableDataStream:getItemIndex()

    データストリーム内のアイテムの現在のインデックスを返します。

    このメソッドは、FlowAPI クラスの executeDataStreamAction() メソッドから返された ScriptableDataStream オブジェクトに対してのみ呼び出すことができます。「FlowAPI」を参照してください。

    表 : 3. パラメーター
    名前 タイプ 説明
    なし
    表 : 4. 返される内容
    タイプ 説明
    番号 0 ベースのインデックスを使用するデータストリーム内のアイテムの現在のインデックス。
    (function() {
    	
    	try {
    
    		// Execute Data Stream Action. 
    		var stream = sn_fd.FlowAPI.executeDataStreamAction('x_my_scope.data_stream_name');
    
    		// Process each item in the data stream
    		while (stream.hasNext()) {
    
    			// Get a single item from the data stream.
    			var User = stream.next();
    
    			// Use the item. Example:
    			// var now_GR = new GlideRecord(<table_name>);
    			// now_GR.<field_name> = User.<field_name>;
    			// now_GR.insert();
    		
    			// By default, this code snippet will terminate after 10 items.
    			// Remove or modify this limit after your code has been tested.
    			if (stream.getItemIndex() >= 9) {
    				break;
    			}
    		}		
    	} catch (ex) {
    		var message = ex.getMessage();
    		gs.error(message);
    	} finally {
    		stream.close();
    	}
    	
    })();

    ScriptableDataStream:getItemInPageIndex()

    データストリームの現在のページ内のアイテムの現在のインデックスを返します。

    このメソッドは、FlowAPI クラスの executeDataStreamAction() メソッドから返された ScriptableDataStream オブジェクトに対してのみ呼び出すことができます。「FlowAPI」を参照してください。

    表 : 5. パラメーター
    名前 タイプ 説明
    なし
    表 : 6. 返される内容
    タイプ 説明
    番号 0 ベースのインデックスを使用する、データストリーム内の現在のページ内のアイテムの現在のインデックス。
    (function() {
    	
    	try {
    ​
    		// Execute Data Stream Action. 
    		var stream = sn_fd.FlowAPI.executeDataStreamAction('x_snc_my_scope.data_stream_name');
    ​
    		// Process each item in the data stream
    		while (stream.hasNext()) {
    ​
    			// Get a single item from the data stream.
    			var user = stream.next();
    		
    			// Only log the first item in each page
    			if (stream.getItemInPageIndex() == 0) {
    				gs.info('first user on page is ' + user.name);
    			}
    		}		
    	} catch (ex) {
    		var message = ex.getMessage();
    		gs.error(message);
    	} finally {
    		stream.close();
    	}
    	
    })();

    ScriptableDataStream:getPageIndex()

    データストリーム内のページの現在のインデックスを返します。

    このメソッドは、FlowAPI クラスの executeDataStreamAction() メソッドから返された ScriptableDataStream オブジェクトに対してのみ呼び出すことができます。「FlowAPI」を参照してください。

    表 : 7. パラメーター
    名前 タイプ 説明
    なし
    表 : 8. 返される内容
    タイプ 説明
    番号 0 ベースのインデックスを使用するデータストリーム内のページの現在のインデックス。
    (function() {
    	
    	try {
    
    		// Execute Data Stream Action. 
    		var stream = sn_fd.FlowAPI.executeDataStreamAction('x_my_scope.data_stream_name');
    
    		// Process each item in the data stream
    		while (stream.hasNext()) {
    
    			// Get a single item from the data stream.
    			var item = stream.next();
    
    			// Use the item. 
    			var now_GR = new GlideRecord('incident');
    			now_GR.setValue('number',item.id);
    			now_GR.setValue('short_description',item.name);
    			now_GR.insert();
    		
    			// By default, this code snippet will terminate after 5 pages.
    			// Remove or modify this limit after testing your code.
    			if (stream.getPageIndex() >= 4) {
    				break;
    			}
    		}		
    	} catch (ex) {
    		var message = ex.getMessage();
    		gs.error(message);
    	} finally {
    		stream.close();
    	}
    	
    })();

    ScriptableDataStream:hasNext()

    データストリームにさらに多くのアイテムがある場合は true を返します。

    このメソッドは、FlowAPI クラスの executeDataStreamAction() メソッドから返された ScriptableDataStream オブジェクトに対してのみ呼び出すことができます。「FlowAPI」を参照してください。

    注:
    デフォルトでは、1 ページのデータを MID サーバー から取得する際にインスタンスは 600 秒間待機します。MID サーバーデータストリーム アクションを実行しているときにタイムアウトが発生した場合は、datastream_alternative_env_fetch_page_timeout_seconds システムプロパティを増やしてこのデフォルトを変更します。
    表 : 9. パラメーター
    名前 タイプ 説明
    なし
    表 : 10. 返される内容
    タイプ 説明
    ブーリアン データストリームにさらに多くのアイテムがあるかどうかを判断するフラグ。次の値が含まれます。
    • true:データストリームで反復処理するアイテムが他にもあります。
    • false:データストリームにこれ以上アイテムはありません。

    この例では、データストリームで返される各アイテムのインシデントレコードを作成します。

    (function() {
    	
    	try {
    
    		// Execute Data Stream Action. 
    		var stream = sn_fd.FlowAPI.executeDataStreamAction('x_my_scope.data_stream_name');
    
    		// Process each item in the data stream
    		while (stream.hasNext()) {
    
    			// Get a single item from the data stream.
    			var item = stream.next();
    
    			// Use the item. 
    			var now_GR = new GlideRecord('incident');
    			now_GR.setValue('number',item.id);
    			now_GR.setValue('short_description',item.name);
    			now_GR.insert();
    		
    			// By default, this code snippet will terminate after 10 items.
    			// Remove or modify this limit after testing your code.
    			if (stream.getItemIndex() >= 9) {
    				break;
    			}
    		}		
    	} catch (ex) {
    		var message = ex.getMessage();
    		gs.error(message);
    	} finally {
    		stream.close();
    	}
    	
    })();

    ScriptableDataStream:next()

    データストリームの次のアイテムを返します。

    このメソッドは、FlowAPI クラスの executeDataStreamAction() メソッドから返された ScriptableDataStream オブジェクトに対してのみ呼び出すことができます。「FlowAPI」を参照してください。

    注:
    デフォルトでは、1 ページのデータを MID サーバー から取得する際にインスタンスは 600 秒間待機します。MID サーバーデータストリーム アクションを実行しているときにタイムアウトが発生した場合は、datastream_alternative_env_fetch_page_timeout_seconds システムプロパティを増やしてこのデフォルトを変更します。
    表 : 11. パラメーター
    名前 タイプ 説明
    なし
    表 : 12. 返される内容
    タイプ 説明
    オブジェクト データストリームの次のアイテム。このオブジェクトには、データストリームアクションで定義された出力が含まれます。データストリームアクションの出力を表示するには、フローデザイナーインターフェイスのデータストリームアクションの [出力] セクションに移動します。

    この例では、データストリームで返される各アイテムのインシデントレコードを作成します。

    (function() {
    	
    	try {
    
    		// Execute Data Stream Action. 
    		var stream = sn_fd.FlowAPI.executeDataStreamAction('x_my_scope.data_stream_name');
    
    		// Process each item in the data stream
    		while (stream.hasNext()) {
    
    			// Get a single item from the data stream.
    			var item = stream.next();
    
    			// Use the item. 
    			var now_GR = new GlideRecord('incident');
    			now_GR.setValue('number',item.id);
    			now_GR.setValue('short_description',item.name);
    			now_GR.insert();
    		
    			// By default, this code snippet will terminate after 10 items.
    			// Remove or modify this limit after testing your code.
    			if (stream.getItemIndex() >= 9) {
    				break;
    			}
    		}		
    	} catch (ex) {
    		var message = ex.getMessage();
    		gs.error(message);
    	} finally {
    		stream.close();
    	}
    	
    })();