---
sourceDocument: オーストラリア API リファレンス
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ja-JP/api-reference

 Release :

    - australia

ft:locale :

    - ja-JP

ft:publication_title :

    - オーストラリア API リファレンス

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

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

# ScriptableDataStream - スコープ付き、グローバル {#ariaid-title1}

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

ScriptableDataStream API は、データのストリームを操作するためのメソッドを提供します。

このクラスは、次のいずれかの API を使用して ScriptableDataStream オブジェクトを取得した後にのみ、サーバー側スクリプトで使用できます。  
* FlowAPI クラスの executeDataStreamAction() メソッド。「 [FlowAPI」](https://servicenow-prod.fluidtopics.net/osXslvYuadnMZWGApo4tFg#ScriptableFlowAPI "FlowAPI は、ブロックまたは非ブロックのいずれかを使用して、サーバー側スクリプトでアクション、フロー、またはサブフローを実行するメソッドを提供します。")を参照してください。
* ScriptableFlowRunnerResult クラスの getDataStream() メソッド。「 [ScriptableFlowRunnerResult](https://servicenow-prod.fluidtopics.net/IanWWPBtnrrczJSbdO8fyg#ScriptableFlowRunnerResultScopedAPI "ScriptableFlowRunner を使用してフロー、サブフロー、またはアクションを実行した結果をキャプチャします。コンテキスト ID、ドメイン、フロー実行の出力などのデータが含まれます。")」を参照してください。
{#ScriptableDataStreamAPI__ul_wnh_sfv_ylb}

ScriptableDataStream オブジェクトを取得した後、次の特定の順序でメソッドを呼び出します。  
1. [hasNext()](https://servicenow-prod.fluidtopics.net/IEW2k~CAZA6Zx_UeKs5raA#ScriptableDS-hasNext "データストリームにさらに多くのアイテムがある場合は true を返します。") メソッドを使用して、データストリームにさらに項目があるかどうかを判断します。
2. [next()](https://servicenow-prod.fluidtopics.net/IEW2k~CAZA6Zx_UeKs5raA#ScriptableDS-next "データストリームの次のアイテムを返します。") メソッドを使用して、ストリーム内の次のアイテムにアクセスします。
3. [getItemIndex()、](https://servicenow-prod.fluidtopics.net/IEW2k~CAZA6Zx_UeKs5raA#ScriptableDS-getItemIndex "データストリーム内のアイテムの現在のインデックスを返します。")[getItemInPageIndex()](https://servicenow-prod.fluidtopics.net/IEW2k~CAZA6Zx_UeKs5raA#ScriptableDS-getItemInPageIndex "データストリームの現在のページ内のアイテムの現在のインデックスを返します。")、および [getPageIndex()](https://servicenow-prod.fluidtopics.net/IEW2k~CAZA6Zx_UeKs5raA#ScriptableDS-getPageIndex "データストリーム内のページの現在のインデックスを返します。") メソッドを使用して、ストリームから情報を取得します。
4. [close()](https://servicenow-prod.fluidtopics.net/IEW2k~CAZA6Zx_UeKs5raA#ScriptableDS-close "データストリームへの接続を閉じます。データストリームで必要な操作を実行した後は、必ずこのメソッドを呼び出します。") メソッドを使用してストリームを閉じます。
{#ScriptableDataStreamAPI__ol_k1k_yp1_3jb}

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

## ScriptableDataStream:close() {#ariaid-title2}

データストリームへの接続を閉じます。データストリームで必要な操作を実行した後は、必ずこのメソッドを呼び出します。
このメソッドは、FlowAPI クラスの executeDataStreamAction() メソッドから返された ScriptableDataStream オブジェクトに対してのみ呼び出すことができます。「[FlowAPI](https://servicenow-prod.fluidtopics.net/osXslvYuadnMZWGApo4tFg#ScriptableFlowAPI "FlowAPI は、ブロックまたは非ブロックのいずれかを使用して、サーバー側スクリプトでアクション、フロー、またはサブフローを実行するメソッドを提供します。")」を参照してください。
{#ScriptableDS-close__table_idv_glc_cjb__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| なし |   |   |
[表 : 1. パラメーター]

{#ScriptableDS-close__table_idv_glc_cjb} {#ScriptableDS-close__table_jdv_glc_cjb__entry__2}

| タイプ | 説明 |
|-|-|
| なし |   |
[表 : 2. 返される内容]

{#ScriptableDS-close__table_jdv_glc_cjb}  

    (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() {#ariaid-title3}

データストリーム内のアイテムの現在のインデックスを返します。
このメソッドは、FlowAPI クラスの executeDataStreamAction() メソッドから返された ScriptableDataStream オブジェクトに対してのみ呼び出すことができます。「[FlowAPI](https://servicenow-prod.fluidtopics.net/osXslvYuadnMZWGApo4tFg#ScriptableFlowAPI "FlowAPI は、ブロックまたは非ブロックのいずれかを使用して、サーバー側スクリプトでアクション、フロー、またはサブフローを実行するメソッドを提供します。")」を参照してください。
{#ScriptableDS-getItemIndex__table_ic4_flc_cjb__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| なし |   |   |
[表 : 3. パラメーター]

{#ScriptableDS-getItemIndex__table_ic4_flc_cjb} {#ScriptableDS-getItemIndex__table_jc4_flc_cjb__entry__2}

| タイプ | 説明 |
|-|-|
| 番号 | 0 ベースのインデックスを使用するデータストリーム内のアイテムの現在のインデックス。 |
[表 : 4. 返される内容]

{#ScriptableDS-getItemIndex__table_jc4_flc_cjb}  

    (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() {#ariaid-title4}

データストリームの現在のページ内のアイテムの現在のインデックスを返します。
このメソッドは、FlowAPI クラスの executeDataStreamAction() メソッドから返された ScriptableDataStream オブジェクトに対してのみ呼び出すことができます。「[FlowAPI](https://servicenow-prod.fluidtopics.net/osXslvYuadnMZWGApo4tFg#ScriptableFlowAPI "FlowAPI は、ブロックまたは非ブロックのいずれかを使用して、サーバー側スクリプトでアクション、フロー、またはサブフローを実行するメソッドを提供します。")」を参照してください。
{#ScriptableDS-getItemInPageIndex__table_mg4_zkc_cjb__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| なし |   |   |
[表 : 5. パラメーター]

{#ScriptableDS-getItemInPageIndex__table_mg4_zkc_cjb} {#ScriptableDS-getItemInPageIndex__table_ng4_zkc_cjb__entry__2}

| タイプ | 説明 |
|-|-|
| 番号 | 0 ベースのインデックスを使用する、データストリーム内の現在のページ内のアイテムの現在のインデックス。 |
[表 : 6. 返される内容]

{#ScriptableDS-getItemInPageIndex__table_ng4_zkc_cjb}  

    (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() {#ariaid-title5}

データストリーム内のページの現在のインデックスを返します。
このメソッドは、FlowAPI クラスの executeDataStreamAction() メソッドから返された ScriptableDataStream オブジェクトに対してのみ呼び出すことができます。「[FlowAPI](https://servicenow-prod.fluidtopics.net/osXslvYuadnMZWGApo4tFg#ScriptableFlowAPI "FlowAPI は、ブロックまたは非ブロックのいずれかを使用して、サーバー側スクリプトでアクション、フロー、またはサブフローを実行するメソッドを提供します。")」を参照してください。
{#ScriptableDS-getPageIndex__table_l3t_g43_bjb__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| なし |   |   |
[表 : 7. パラメーター]

{#ScriptableDS-getPageIndex__table_l3t_g43_bjb} {#ScriptableDS-getPageIndex__table_m3t_g43_bjb__entry__2}

| タイプ | 説明 |
|-|-|
| 番号 | 0 ベースのインデックスを使用するデータストリーム内のページの現在のインデックス。 |
[表 : 8. 返される内容]

{#ScriptableDS-getPageIndex__table_m3t_g43_bjb}  

    (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() {#ariaid-title6}

データストリームにさらに多くのアイテムがある場合は true を返します。
このメソッドは、FlowAPI クラスの executeDataStreamAction() メソッドから返された ScriptableDataStream オブジェクトに対してのみ呼び出すことができます。「[FlowAPI](https://servicenow-prod.fluidtopics.net/osXslvYuadnMZWGApo4tFg#ScriptableFlowAPI "FlowAPI は、ブロックまたは非ブロックのいずれかを使用して、サーバー側スクリプトでアクション、フロー、またはサブフローを実行するメソッドを提供します。")」を参照してください。  
注:  
デフォルトでは、1 ページのデータを MID サーバー から取得する際にインスタンスは 600 秒間待機します。MID サーバー で データストリーム アクションを実行しているときにタイムアウトが発生した場合は、datastream_alternative_env_fetch_page_timeout_seconds システムプロパティを増やしてこのデフォルトを変更します。
{#ScriptableDS-hasNext__table_fcx_d43_bjb__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| なし |   |   |
[表 : 9. パラメーター]

{#ScriptableDS-hasNext__table_fcx_d43_bjb} {#ScriptableDS-hasNext__table_gcx_d43_bjb__entry__2}

| タイプ | 説明 |
|-|-|
| ブーリアン | データストリームにさらに多くのアイテムがあるかどうかを判断するフラグ。次の値が含まれます。 * true:データストリームで反復処理するアイテムが他にもあります。 * false:データストリームにこれ以上アイテムはありません。 {#ScriptableDS-hasNext__ul_xy5_z4d_cjb} |
[表 : 10. 返される内容]

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

    (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() {#ariaid-title7}

データストリームの次のアイテムを返します。
このメソッドは、FlowAPI クラスの executeDataStreamAction() メソッドから返された ScriptableDataStream オブジェクトに対してのみ呼び出すことができます。「[FlowAPI](https://servicenow-prod.fluidtopics.net/osXslvYuadnMZWGApo4tFg#ScriptableFlowAPI "FlowAPI は、ブロックまたは非ブロックのいずれかを使用して、サーバー側スクリプトでアクション、フロー、またはサブフローを実行するメソッドを提供します。")」を参照してください。  
注:  
デフォルトでは、1 ページのデータを MID サーバー から取得する際にインスタンスは 600 秒間待機します。MID サーバー で データストリーム アクションを実行しているときにタイムアウトが発生した場合は、datastream_alternative_env_fetch_page_timeout_seconds システムプロパティを増やしてこのデフォルトを変更します。
{#ScriptableDS-next__table_lrc_f43_bjb__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| なし |   |   |
[表 : 11. パラメーター]

{#ScriptableDS-next__table_lrc_f43_bjb} {#ScriptableDS-next__table_mrc_f43_bjb__entry__2}

| タイプ | 説明 |
|-|-|
| オブジェクト | データストリームの次のアイテム。このオブジェクトには、データストリームアクションで定義された出力が含まれます。データストリームアクションの出力を表示するには、フローデザイナーインターフェイスのデータストリームアクションの \[出力\] セクションに移動します。 |
[表 : 12. 返される内容]

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

    (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();
    	}
    	
    })();


