ScriptableDataStream - スコープ指定、グローバル
ScriptableDataStream API は、データのストリームとやり取りするためのメソッドを提供します。
このクラスは、次のいずれかの API を使用して ScriptableDataStream オブジェクトを取得した後のサーバー側スクリプトでのみ使用できます。
- FlowAPI クラスの executeDataStreamAction() メソッド。「 FlowAPI」を参照してください。
- ScriptableFlowRunnerResult クラスの getDataStream() メソッド。「ScriptableFlowRunnerResult」を参照して下さい。
ScriptableDataStream オブジェクトを取得した後、次の順序でメソッドを呼び出します。
- hasNext() メソッドを使用して、データストリーム内にまだアイテムがあるかどうかを判断します。
- next() メソッドを使用して、ストリーム内の次のアイテムにアクセスします。
- getItemIndex()、getItemInPageIndex()、および getPageIndex() メソッドを使用して、ストリームから情報を取得します。
- close() メソッドを使用してストリームを閉じます。
このクラスは sn_fd 名前空間で実行されます。
try/catch ブロックで囲みます。データストリームを閉じてパフォーマンスの問題を防ぐために、常に、ScriptableDataStream クラスの close() メソッドで終了する finally ステートメントを含めます。ScriptableDataStream - close()
データストリームへの接続を閉じます。データストリームで必要な操作を実行した後は、常にこのメソッドを呼び出します。
このメソッドは、FlowAPI クラスの executeDataStreamAction() メソッドから返された ScriptableDataStream オブジェクトに対してのみ呼び出すことができます。「FlowAPI」を参照してください。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| なし |
(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」を参照してください。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 数字 | ゼロベースのインデックスを使用したデータストリーム内のアイテムの現在のインデックス。 |
(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」を参照してください。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 数字 | ゼロベースのインデックスを使用したデータストリームの現在のページにあるアイテムの現在のインデックス。 |
(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」を参照してください。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 数字 | ゼロベースのインデックスを使用したデータストリーム内のページの現在のインデックス。 |
(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」を参照してください。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| ブーリアン | データストリーム内にまだアイテムがあるかどうかを判断するフラグ。次の値が含まれます。
|
この例は、データストリームで返された各アイテムのインシデントレコードを作成します。
(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」を参照してください。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| オブジェクト | データストリーム内の次のアイテム。このオブジェクトには、データストリームアクションによって定義された出力が含まれます。データストリームアクションの出力を表示するには、Flow Designer インターフェイスのデータストリームアクションの [出力] セクションに移動します。 |
この例は、データストリームで返された各アイテムのインシデントレコードを作成します。
(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();
}
})();