---
sourceDocument: ブラジル アプリケーションのビルドまたは変更
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ja-JP/application-development

 Release :

    - brazil

ft:locale :

    - ja-JP

ft:publication_title :

    - ブラジル アプリケーションのビルドまたは変更

ft:clusterId :

    - cadev

bundleId :

    - cadev

workflow :

    - Development, Data, and Analytics


---

# フロー API

# フロー API - ServiceNow Fluent {#fluent-flow-api__fluent-api-title}

リリースバージョン: Brazil  
更新日 2026年09月10日  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 所要時間：72分  
フロー API は、再利用可能な複数ステップコンポーネントを使用してビジネスプロセスを自動化するフローとサブフロー \[sys_hub_flow\] を定義します。
注:  
最新の ServiceNow Fluent API ドキュメントと例については、 [ServiceNow Fluent API リファレンス](https://servicenow.github.io/sdk/category/api-reference) および [ServiceNow SDK のサンプルリポジトリ](https://github.com/ServiceNow/sdk-examples) ( GitHub)。

フローオブジェクトを使用してフローを作成します。詳細については、「[フローオブジェクト](https://servicenow-prod.fluidtopics.net/y34uNCkew6iimGPgrKlGpA#fluent-flow-object "一連のトリガー条件が発生したときに一連のアクションとフローロジックを実行するフロー [sys_hub_flow] を作成します。")」を参照してください。

Subflow オブジェクトを使用してサブフローを作成します。詳細については、「[サブフローオブジェクト](https://servicenow-prod.fluidtopics.net/y34uNCkew6iimGPgrKlGpA#fluent-subflow-object "サブフロー [sys_hub_flow] を作成して、フローまたは API によって呼び出されたときに、再利用可能な一連のアクションとフローロジックを実行します。")」を参照してください。

フローに関する一般的な情報については、「 [Exploring flows](https://www.servicenow.com/docs/access?context=exploring-flows&version=brazil&pubname=brazil-build-workflows&ft:locale=en-US)」を参照してください。サブフローに関する一般的な情報については、「 [Exploring subflows](https://www.servicenow.com/docs/access?context=exploring-subflows&version=brazil&pubname=brazil-build-workflows&ft:locale=en-US)」を参照してください。{#fluent-flow-api__fluent-api-general-info}
**関連概念**   

* [ServiceNow Fluent](https://servicenow-prod.fluidtopics.net/6reqwtT2w5E4H4MCs9So9w "ServiceNow Fluent ドメイン固有のプログラミング言語を使用して、ソースコードでアプリケーションメタデータを定義します。")

## フローオブジェクト {#fluent-flow-object__fluent-object-title}

一連のトリガー条件が発生したときに一連のアクションとフローロジックを実行するフロー \[sys_hub_flow\] を作成します。
フローは、トリガー条件が満たされた場合にのみ実行されます。一貫性のある事前定義されたトリガーを必要とするイベント駆動型の自動化にはフローを使用します。  
フローオブジェクトは次のコンポーネントで構成されます。

* フロー構成プロパティを定義する 1 つの構成オブジェクト。
* フローを実行するタイミングを定義する1つのwfa.trigger関数。
* 実行するアクションとフローロジックを定義する One Body 関数。
  * 0個以上のwfa.action関数
  * 0 個以上のwfa.flow_logic関数
  {#fluent-flow-object__ul_amj_kpj_xhc}
{#fluent-flow-object__ul_rqx_bsv_whc}
{#fluent-flow-object__table_dyc_v5n_rhc__entry__3}{#fluent-flow-object__now-id-desc2}

| 名前 | タイプ | 説明 |
|-|-|-|
| 構成 | オブジェクト | 必須。Fluent オブジェクトまたは関数のメタデータ構成プロパティを含むオブジェクト。 |
| $id | 文字列または数値 | 必須。メタデータオブジェクトの一意の ID。アプリケーションをビルドすると、この ID は一意のsys_idにハッシュされます。詳細については、「[ServiceNow Fluent 言語構成](https://servicenow-prod.fluidtopics.net/dSv2_sKS5nR8QxKtIHLmPQ "ServiceNow Fluent 言語構成は、 ServiceNow Fluent API を使用してソースコードで開発するための追加機能を提供します。")」を参照してください。 形式: `Now.ID['string' or number]` |
| 名前 | 文字列 | 必須。フローの表示名。フロー名は、目的を簡単に識別できるように、わかりやすくわかりやすいものにする必要があります。 |
| 説明 | 文字列 | フローの内容の説明。 |
| runAs | 文字列 | フローアクションが実行されるユーザーコンテキストを決定します。システムユーザー設定は、ロールベースの ACL をバイパスする特権ユーザーとして実行されます。ユーザー設定は、フローを開始したユーザーの権限とロールで実行されます。 有効な値:system、user デフォルト:ユーザー |
| runWithRoles | 文字列 | フローの実行中に使用するロールを指定します。ロールを使用してフローを実行する方法の詳細については、「 [Flow roles](https://www.servicenow.com/docs/access?context=flow-roles&version=brazil&pubname=brazil-build-workflows&ft:locale=en-US)」を参照してください。 |
| flowPriority | 文字列 | フローエンジンでフローの実行優先度を定義します。 有効な値:低、中、高 デフォルト:中 |
| 保護 | 文字列 | フローが読み取り専用 (読み取り) か編集可能 (空の文字列) かを定義します。 有効な値:read、'' デフォルト値:'' |
| アクセス | 文字列 | フローがパブリックかプライベートかを定義します。 有効な値：public、package_private デフォルト：public |
| flowVariables | オブジェクト | 列タイプを使用してフローで使用できるデータ変数を定義するオブジェクト。get_table_schema関数を使用して、フィールド定義をフェッチします。 |
| wfa.trigger | 関数 | フローを実行するタイミングを定義します。トリガー条件が満たされると、トリガーによって提供されたデータを使用してフローが実行されます。wfa.trigger関数の詳細については、「[wfa.trigger 関数](https://servicenow-prod.fluidtopics.net/y34uNCkew6iimGPgrKlGpA#fluent-wfa-trigger-function "特定のトリガータイプの開始条件が満たされたときにフローを実行します。トリガーは、フローがいつ実行されるか、およびフロー開始条件からどのデータが利用可能かを決定します。")」を参照してください。 |
| フロー本文 | 関数 | Flow body は、フロー内の実行ステップを表す TypeScript の Arrow function です。フロー本体は、wfa.trigger オブジェクトと flowVariables オブジェクトを含む params パラメーターを入力として受け取ります。Flow bodyのステップは、次の機能タイプで構成されます。 * wfa.action 関数:レコードの作成、メールの送信、承認の要求、外部システムとの統合など、フロー内の特定のタスクと操作を実行します。wfa.action関数の詳細については、「[wfa.action 関数](https://servicenow-prod.fluidtopics.net/y34uNCkew6iimGPgrKlGpA#fluent-wfa-action-function "フローまたはサブフローから特定のアクションインスタンスを実行します。アクションは、どのデータが生成、更新、または取得されるかを決定します。")」を参照してください。 * wfa.flow_logic function:フローの実行方法を制御し、条件分岐、反復、およびフロー構造化機能を提供します。wfa.flow_logic関数の詳細については、「[wfa.flow_logic 関数](https://servicenow-prod.fluidtopics.net/y34uNCkew6iimGPgrKlGpA#fluent-wfa-flow_logic-function "フローまたはサブフローから特定のフローロジックインスタンスを実行します。フローロジックは、データを使用するタイミングと方法を決定します。")」を参照してください。 {#fluent-flow-object__ul_nmd_wc4_rhc} これらのパラメーター値は、フロー本文関数で使用できます。 params.trigger.current :   データタイプ:レコード。レコードの作成、レコードの更新、またはレコードの作成または更新フローを開始した現在のレコードを格納するパラメーター。 params.trigger.previous :   データタイプ:レコード。更新レコードフローを開始した以前のレコード値を格納するパラメーター。 params.trigger.table_name :   データタイプ:文字列。フローを開始した現在のレコードのテーブル名を格納するパラメーター。 params.trigger.flowVariables :   データタイプ:オブジェクト。このフローで定義されたフロー変数を格納するパラメーター。 |
[表 : 1. プロパティ]

{#fluent-flow-object__table_dyc_v5n_rhc}  
この例では、起点フィールド値が空のインシデントが作成されたときに実行されるフローを作成します。フローは、インシデントの重大度に基づいてマネージャーとチームメンバーにアラートを送信します。

    import { action, Flow, wfa, trigger } from '@servicenow/sdk/automation'

    export const incidentSeverityAlertFlow = Flow(
        {
            $id: Now.ID['incident_severity_alert_flow'],
            name: 'Incident Severity Alert Flow',
            description: 'Alerts managers and team members based on incident severity for incidents with empty origin',
        },
        wfa.trigger(
            trigger.record.created,
            { $id: Now.ID['empty_origin_incident_trigger'] },
            {
                table: 'incident',
                condition: 'origin=NULL',
                run_flow_in: 'background',
                run_on_extended: 'false',
                run_when_setting: 'both',
                run_when_user_setting: 'any',
                run_when_user_list: [],
            }
        ),
        (params) => {
            wfa.action(
                action.core.log,
                { $id: Now.ID['log_incident_short_description'] },
                {
                    log_level: 'info',
                    log_message: `Incident created: ${wfa.dataPill(params.trigger.current.short_description, 'string')}`,
                }
            )

            wfa.flowLogic.if(
                {
                    $id: Now.ID['check_severity_high'],
                    condition: `${wfa.dataPill(params.trigger.current.severity, 'string')}=1`,
                    annotation: 'High severity (1)',
                },
                () => {
                    const assignmentGroup = wfa.action(
                        action.core.lookUpRecord,
                        { $id: Now.ID['lookup_assignment_group'] },
                        {
                            table: 'sys_user_group',
                            conditions: `sys_id=${wfa.dataPill(params.trigger.current.assignment_group, 'reference')}`,
                            sort_type: 'sort_asc',
                            if_multiple_records_are_found_action: 'use_first_record',
                        }
                    )

                    const manager = wfa.action(
                        action.core.lookUpRecord,
                        { $id: Now.ID['lookup_manager_details'] },
                        {
                            table: 'sys_user',
                            conditions: `sys_id=${wfa.dataPill(assignmentGroup.Record.manager, 'reference')}`,
                            sort_type: 'sort_asc',
                            if_multiple_records_are_found_action: 'use_first_record',
                        }
                    )

                    wfa.action(
                        action.core.sendNotification,
                        { $id: Now.ID['send_urgent_email_to_manager'] },
                        {
                            table_name: 'incident',
                            record: wfa.dataPill(params.trigger.current.sys_id, 'reference'),
                            notification: 'high_severity_incident_manager_notification',
                        }
                    )

                    wfa.flowLogic.forEach(
                        wfa.dataPill(params.trigger.current.additional_assignee_list, 'array.string'),
                        { $id: Now.ID['foreach_additional_assignees_high'] },
                        () => {
                            const assignee = wfa.action(
                                action.core.lookUpRecord,
                                { $id: Now.ID['lookup_assignee_details_high'] },
                                {
                                    table: 'sys_user',
                                    conditions: `sys_id=${wfa.dataPill(params.trigger.current.additional_assignee_list, 'array.string')}`,
                                    sort_type: 'sort_asc',
                                    if_multiple_records_are_found_action: 'use_first_record',
                                }
                            )

                            wfa.action(
                                action.core.sendSms,
                                { $id: Now.ID['send_sms_to_assignee_high'] },
                                {
                                    recipients: `${wfa.dataPill(assignee.Record.phone, 'string')}`,
                                    message: `High severity incident: ${wfa.dataPill(params.trigger.current.short_description, 'string')}`,
                                }
                            )
                        }
                    )

                    wfa.action(
                        action.core.updateRecord,
                        { $id: Now.ID['update_work_notes_high'] },
                        {
                            table_name: 'incident',
                            record: wfa.dataPill(params.trigger.current.sys_id, 'reference'),
                            values: TemplateValue({
                                work_notes: `Manager ${wfa.dataPill(manager.Record.name, 'string')} notified via email and team notified via SMS.`,
                            }),
                        }
                    )
                }
            )

            wfa.flowLogic.elseIf(
                {
                    $id: Now.ID['check_severity_medium'],
                    condition: `${wfa.dataPill(params.trigger.current.severity, 'string')}=2`,
                    annotation: 'Medium severity (2)',
                },
                () => {
                    wfa.flowLogic.forEach(
                        wfa.dataPill(params.trigger.current.additional_assignee_list, 'array.string'),
                        { $id: Now.ID['foreach_additional_assignees_medium'] },
                        () => {
                            const assignee = wfa.action(
                                action.core.lookUpRecord,
                                { $id: Now.ID['lookup_assignee_details_medium'] },
                                {
                                    table: 'sys_user',
                                    conditions: `sys_id=${wfa.dataPill(params.trigger.current.additional_assignee_list, 'array.string')}`,
                                    sort_type: 'sort_asc',
                                    if_multiple_records_are_found_action: 'use_first_record',
                                }
                            )

                            wfa.action(
                                action.core.sendSms,
                                { $id: Now.ID['send_sms_to_assignee_medium'] },
                                {
                                    recipients: `${wfa.dataPill(assignee.Record.phone, 'string')}`,
                                    message: `Medium severity incident: ${wfa.dataPill(params.trigger.current.short_description, 'string')}`,
                                }
                            )
                        }
                    )
                }
            )

            wfa.action(
                action.core.updateRecord,
                { $id: Now.ID['update_incident_to_in_progress'] },
                {
                    table_name: 'incident',
                    record: wfa.dataPill(params.trigger.current.sys_id, 'reference'),
                    values: TemplateValue({ state: '2' }),
                }
            )
        }
    )

この例は、変更要求が承認され、要求者に通知されたときに実行されます。

    import { action, Flow, wfa, trigger } from '@servicenow/sdk/automation'

    export const changeRequestApprovalNotificationFlow = Flow(
        {
            $id: Now.ID['change_request_approval_notification_flow'],
            name: 'Change Request Approval Notification Flow',
            description: 'Sends formatted notification to requester when change request is approved',
        },
        wfa.trigger(
            trigger.record.updated,
            { $id: Now.ID['change_request_approved_trigger'] },
            {
                table: 'change_request',
                condition: 'approval=approved',
                run_flow_in: 'background',
                trigger_strategy: 'unique_changes',
                run_when_user_list: [],
                run_when_setting: 'both',
                run_on_extended: 'false',
                run_when_user_setting: 'any',
            }
        ),
        (params) => {
            const requester = wfa.action(
                action.core.lookUpRecord,
                { $id: Now.ID['lookup_requester_details'] },
                {
                    table: 'sys_user',
                    conditions: `sys_id=${wfa.dataPill(params.trigger.current.requested_by, 'reference')}`,
                    sort_type: 'sort_asc',
                    if_multiple_records_are_found_action: 'use_first_record',
                }
            )

            wfa.action(
                action.core.sendEmail,
                { $id: Now.ID['send_approval_notification_email'] },
                {
                    table_name: 'change_request',
                    watermark_email: true,
                    ah_subject: `Change Request ${wfa.dataPill(params.trigger.current.number, 'string')} - Approved`,
                    ah_body: `Your change request has been approved.`,
                    record: wfa.dataPill(params.trigger.current.sys_id, 'reference'),
                    ah_to: wfa.dataPill(requester.Record.email, 'string'),
                }
            )

            wfa.action(
                action.core.updateRecord,
                { $id: Now.ID['update_work_notes_notification_sent'] },
                {
                    table_name: 'change_request',
                    record: wfa.dataPill(params.trigger.current.sys_id, 'reference'),
                    values: TemplateValue({
                        work_notes: `Approval notification sent to ${wfa.dataPill(requester.Record.name, 'string')} (${wfa.dataPill(requester.Record.email, 'string')})`,
                    }),
                }
            )
        }
    )

## サブフローオブジェクト {#fluent-subflow-object__fluent-object-title}

サブフロー \[sys_hub_flow\] を作成して、フローまたは API によって呼び出されたときに、再利用可能な一連のアクションとフローロジックを実行します。
サブフローは、フローまたは API によって呼び出されたときに実行されます。複数のフローで呼び出すことができるオンデマンド自動化のためにサブフローを使用します。  
サブフローは次のコンポーネントで構成されています。

* サブフロー構成プロパティを定義する 1 つの構成オブジェクト。
  * サブフロー入力を定義する 0 個または 1 個の入力オブジェクト。
  * サブフロー出力を定義するゼロまたは 1 つの出力オブジェクト。
  * フロー変数を定義する 0 個または 1 個のフロー変数オブジェクト。
  {#fluent-subflow-object__ul_mz4_h4l_xhc}
* 実行するアクション、フローロジック、およびサブフローを定義する 1 つの本文機能。
  * 0個以上のwfa.action関数
  * 0 個以上のwfa.flow_logic関数
  {#fluent-subflow-object__ul_ovq_wnl_xhc}
{#fluent-subflow-object__ul_swz_fsv_whc}
{#fluent-subflow-object__table_ozc_zd4_rhc__entry__3}{#fluent-subflow-object__now-id-desc2}

| 名前 | タイプ | 説明 |
|-|-|-|
| 構成 | オブジェクト | 必須。Fluent オブジェクトまたは関数のメタデータ構成プロパティを含むオブジェクト。 |
| $id | 文字列または数値 | 必須。メタデータオブジェクトの一意の ID。アプリケーションをビルドすると、この ID は一意のsys_idにハッシュされます。詳細については、「[ServiceNow Fluent 言語構成](https://servicenow-prod.fluidtopics.net/dSv2_sKS5nR8QxKtIHLmPQ "ServiceNow Fluent 言語構成は、 ServiceNow Fluent API を使用してソースコードで開発するための追加機能を提供します。")」を参照してください。 形式: `Now.ID['string' or number]` |
| 名前 | 文字列 | 必須。サブフローの表示名。サブフロー名は、その目的を簡単に識別できるように、意味のある説明的なものにする必要があります。このプロパティは、サブフロー構成オブジェクトの一部です。 |
| 説明 | 文字列 | フローの内容の説明。このプロパティは、サブフロー構成オブジェクトの一部です。 |
| runAs | 文字列 | サブフローアクションが実行されるユーザーコンテキストを決定します。 有効な値:system、user デフォルト:ユーザー このプロパティは、サブフロー構成オブジェクトの一部です。 |
| runWithRoles | アレイ | サブフローが実行中に使用するロールを指定します。このプロパティは、サブフロー構成オブジェクトの一部です。 |
| flowPriority | 文字列 | フローエンジンでのサブフローの実行優先度を定義します。 有効な値:低、中、高 デフォルト:中 このプロパティは、サブフロー構成オブジェクトの一部です。 |
| 保護 | 文字列 | サブフローが読み取り専用 (読み取り) か編集可能 (空の文字列) かを定義します。 有効な値:read、' ' このプロパティは、サブフロー構成オブジェクトの一部です。 |
| アクセス | 文字列 | 他のサブフロー作成者に対するサブフローの可視化/アクセシビリティを定義します。 有効な値：public、package_private デフォルト：public このプロパティは、サブフロー構成オブジェクトの一部です。 |
| category | 文字列 | サブフローを整理するためのカテゴリ。このプロパティは、サブフロー構成オブジェクトの一部です。 |
| 入力 | オブジェクト | 列タイプを使用して入力パラメーターを定義するオブジェクト。このプロパティは、サブフロー構成オブジェクトの一部です。 |
| 出力 | オブジェクト | 列タイプを使用して出力パラメーターを定義するオブジェクト。このプロパティは、サブフロー構成オブジェクトの一部です。 |
| flowVariables | オブジェクト | 列タイプを使用してサブフローで使用できるデータ変数を定義するオブジェクト。このプロパティは、サブフロー構成オブジェクトの一部です。 |
| フロー本文 | 関数 | Flow body は、フロー内の実行ステップを表す TypeScript の Arrow function です。フロー本体は、inputs オブジェクトと flowVariables オブジェクトを含む _params パラメーターを入力として受け取ります。Flow bodyのステップは、次の機能タイプで構成されます。 * wfa.action 関数:レコードの作成、メールの送信、承認の要求、外部システムとの統合など、フロー内の特定のタスクと操作を実行します。wfa.action関数の詳細については、「[wfa.action 関数](https://servicenow-prod.fluidtopics.net/y34uNCkew6iimGPgrKlGpA#fluent-wfa-action-function "フローまたはサブフローから特定のアクションインスタンスを実行します。アクションは、どのデータが生成、更新、または取得されるかを決定します。")」を参照してください。 * wfa.flow_logic function:フローの実行方法を制御し、条件分岐、反復、およびフロー構造化機能を提供します。wfa.flow_logic関数の詳細については、「[wfa.flow_logic 関数](https://servicenow-prod.fluidtopics.net/y34uNCkew6iimGPgrKlGpA#fluent-wfa-flow_logic-function "フローまたはサブフローから特定のフローロジックインスタンスを実行します。フローロジックは、データを使用するタイミングと方法を決定します。")」を参照してください。 {#fluent-subflow-object__ul_nmd_wc4_rhc} これらのパラメーター値は、フロー本文関数で使用できます。 _params.trigger.current :   データタイプ:レコード。レコードの作成、レコードの更新、またはレコードの作成または更新フローを開始した現在のレコードを格納するパラメーター。 _params.trigger.previous :   データタイプ:レコード。更新レコードフローを開始した以前のレコード値を格納するパラメーター。 _params.trigger.table_name :   データタイプ:文字列。フローを開始した現在のレコードのテーブル名を格納するパラメーター。 _params.trigger.flowVariables :   データタイプ:オブジェクト。このフローで定義されたフロー変数を格納するパラメーター。 |
[表 : 2. プロパティ]

{#fluent-subflow-object__table_ozc_zd4_rhc}  
この例では、新しいユーザーの名前とオフィスの場所を使用して、ユーザーレコードを検索し、ようこそ通知を送信し、未アサインのハードウェア資産と利用可能なオフィスの場所を検索します。利用可能なラップトップ資産とオフィスの場所がある場合は、それぞれが新しいユーザーに割り当てられます。

    import { Subflow, action, wfa } from '@servicenow/sdk/automation'
    import { BooleanColumn, ReferenceColumn, StringColumn } from '@servicenow/sdk/core'

    export const newUserOnboardingSubflow = Subflow(
        {
            $id: Now.ID['new_user_onboarding_subflow'],
            name: 'New User Onboarding Subflow',
            description: 'Sends welcome notification, assigns laptop and desk, returns assignment results',
            inputs: {
                user_sys_id: ReferenceColumn({
                    label: 'User',
                    referenceTable: 'sys_user',
                    mandatory: true,
                }),
                office_location: ReferenceColumn({
                    label: 'Office Location',
                    referenceTable: 'cmn_location',
                    mandatory: true,
                }),
            },
            outputs: {
                laptop_assigned: BooleanColumn({ label: 'Laptop Assigned' }),
                desk_assigned: BooleanColumn({ label: 'Desk Assigned' }),
                laptop_number: StringColumn({ label: 'Laptop Asset Number', maxLength: 40 }),
                desk_number: StringColumn({ label: 'Desk Asset Number', maxLength: 40 }),
            },
            flowVariables: {
                laptop_found: BooleanColumn({ label: 'Laptop Found Flag', default: false }),
                desk_found: BooleanColumn({ label: 'Desk Found Flag', default: false }),
            },
        },
        (params) => {
            const user = wfa.action(
                action.core.lookUpRecord,
                { $id: Now.ID['lookup_user'] },
                {
                    table: 'sys_user',
                    conditions: `sys_id=${wfa.dataPill(params.inputs.user_sys_id, 'reference')}`,
                    sort_type: 'sort_asc',
                    if_multiple_records_are_found_action: 'use_first_record',
                }
            )

            wfa.action(
                action.core.sendNotification,
                { $id: Now.ID['send_welcome_notification'] },
                {
                    table_name: 'sys_user',
                    record: wfa.dataPill(params.inputs.user_sys_id, 'reference'),
                    notification: 'new_user_welcome_notification',
                }
            )

            const availableLaptop = wfa.action(
                action.core.lookUpRecord,
                { $id: Now.ID['lookup_available_laptop'] },
                {
                    table: 'alm_hardware',
                    conditions: 'assigned_to=NULL^install_status=1^substatus=available',
                    sort_type: 'sort_asc',
                    if_multiple_records_are_found_action: 'use_first_record',
                }
            )

            wfa.flowLogic.if(
                {
                    $id: Now.ID['check_laptop_available'],
                    condition: `${wfa.dataPill(availableLaptop.Record.sys_id, 'reference')}!=NULL`,
                    annotation: 'Available laptop found',
                },
                () => {
                    wfa.action(
                        action.core.updateRecord,
                        { $id: Now.ID['assign_laptop'] },
                        {
                            table_name: 'alm_hardware',
                            record: wfa.dataPill(availableLaptop.Record.sys_id, 'reference'),
                            values: TemplateValue({
                                assigned_to: wfa.dataPill(params.inputs.user_sys_id, 'reference'),
                                install_status: '2',
                                substatus: 'in_use',
                            }),
                        }
                    )
                }
            )

            wfa.flowLogic.else(
                { $id: Now.ID['no_laptop_available'] },
                () => {
                    wfa.action(
                        action.core.log,
                        { $id: Now.ID['log_no_laptop'] },
                        {
                            log_level: 'warn',
                            log_message: `No available laptop found for ${wfa.dataPill(user.Record.name, 'string')} --- manual assignment required.`,
                        }
                    )
                }
            )

            const availableDesk = wfa.action(
                action.core.lookUpRecord,
                { $id: Now.ID['lookup_available_desk'] },
                {
                    table: 'alm_asset',
                    conditions: `assigned_to=NULL^location=${wfa.dataPill(params.inputs.office_location, 'reference')}^install_status=1^substatus=available`,
                    sort_type: 'sort_asc',
                    if_multiple_records_are_found_action: 'use_first_record',
                }
            )

            wfa.flowLogic.if(
                {
                    $id: Now.ID['check_desk_available'],
                    condition: `${wfa.dataPill(availableDesk.Record.sys_id, 'reference')}!=NULL`,
                    annotation: 'Available desk found at office location',
                },
                () => {
                    wfa.action(
                        action.core.updateRecord,
                        { $id: Now.ID['assign_desk'] },
                        {
                            table_name: 'alm_asset',
                            record: wfa.dataPill(availableDesk.Record.sys_id, 'reference'),
                            values: TemplateValue({
                                assigned_to: wfa.dataPill(params.inputs.user_sys_id, 'reference'),
                                install_status: '2',
                                substatus: 'in_use',
                            }),
                        }
                    )
                }
            )

            wfa.flowLogic.else(
                { $id: Now.ID['no_desk_available'] },
                () => {
                    wfa.action(
                        action.core.log,
                        { $id: Now.ID['log_no_desk'] },
                        {
                            log_level: 'warn',
                            log_message: `No available desk at office location for ${wfa.dataPill(user.Record.name, 'string')} --- manual assignment required.`,
                        }
                    )
                }
            )

            wfa.action(
                action.core.sendNotification,
                { $id: Now.ID['send_onboarding_complete'] },
                {
                    table_name: 'sys_user',
                    record: wfa.dataPill(params.inputs.user_sys_id, 'reference'),
                    notification: 'user_onboarding_complete_notification',
                }
            )

            wfa.flowLogic.assignSubflowOutputs(
                {
                    $id: Now.ID['assign_outputs'],
                    annotation: 'Return laptop and desk assignment results',
                },
                params.outputs,
                {
                    laptop_assigned: true,
                    desk_assigned: true,
                    laptop_number: wfa.dataPill(availableLaptop.Record.asset_tag, 'string'),
                    desk_number: wfa.dataPill(availableDesk.Record.asset_tag, 'string'),
                }
            )
        }
    )

## wfa.trigger 関数 {#fluent-wfa-trigger-function__fluent-object-title}

特定のトリガータイプの開始条件が満たされたときにフローを実行します。トリガーは、フローがいつ実行されるか、およびフロー開始条件からどのデータが利用可能かを決定します。
フローオブジェクトのFlow Body関数にwfa.trigger関数を追加します。  
次のタイプのアクションインスタンスがサポートされています。

* trigger.record.created
* trigger.record.updated
* trigger.record.createdOrUpdated
* trigger.scheduled.daily
* trigger.scheduled.weekly
* trigger.scheduled.monthly
* trigger.scheduled.repeat
* trigger.scheduled.runOnce
* trigger.application.inboundEmail
* trigger.application.serviceCatalog
* trigger.application.slaTask
* trigger.application.knowledgeManagement
* trigger.application.remoteTableQuery
{#fluent-wfa-trigger-function__ul_dx3_1lj_c3c}.

使用可能なアクションの詳細については、「 [Workflow Studio flow trigger types](https://www.servicenow.com/docs/access?context=flow-triggers&version=brazil&pubname=brazil-build-workflows&ft:locale=en-US)」を参照してください。
{#fluent-wfa-trigger-function__table_tjy_23k_xhc__entry__3}{#fluent-wfa-trigger-function__now-id-desc2}

| 名前 | タイプ | 説明 |
|-|-|-|
| トリガー | 文字列 | 実行する特定のトリガーの名前。すべてのアクション名には、 `trigger` で始まるドット表記が使用されます。たとえば、 `trigger.record.created`、 `trigger.scheduled.daily`、 `trigger.application.serviceCatalog` などです。 |
| 構成 | オブジェクト | 必須。Fluent オブジェクトまたは関数のメタデータ構成プロパティを含むオブジェクト。 |
| $id | 文字列または数値 | 必須。メタデータオブジェクトの一意の ID。アプリケーションをビルドすると、この ID は一意のsys_idにハッシュされます。詳細については、「[ServiceNow Fluent 言語構成](https://servicenow-prod.fluidtopics.net/dSv2_sKS5nR8QxKtIHLmPQ "ServiceNow Fluent 言語構成は、 ServiceNow Fluent API を使用してソースコードで開発するための追加機能を提供します。")」を参照してください。 形式: `Now.ID['string' or number]` |
| 入力 | オブジェクト | `テーブル`や`条件`など、トリガーに必要な入力パラメーターを含むオブジェクト。 |
[表 : 3. プロパティ]

{#fluent-wfa-trigger-function__table_tjy_23k_xhc}  
この例では、優先度の高いインシデントレコードが作成されたときにフローを実行します。

    // Trigger definition - defines when the flow starts
    wfa.trigger(
        trigger.record.created, // TriggerDefinition - record creation event
        { 
            $id: Now.ID['incident_trigger'], // string | guid, mandatory - unique identifier
            annotation: 'When high priority incident is created' // string, optional - describes trigger purpose
        },
        {
            table: 'incident', // string, mandatory - table name to monitor
            condition: 'priority=1^ORpriority=2', // string, optional - encoded query filter
            run_on_extended: 'false', // string, optional, default: 'false' - run on child tables
            run_flow_in: 'any', // string, optional, default: 'any' - 'any', 'background', or 'foreground'
            run_when_setting: 'both', // string, optional, default: 'both' - 'both', 'non_interactive', or 'interactive'
            run_when_user_list: [], // Array, optional, default: [] - need to use runQuery to get user sys_ids from sys_user table
            run_when_user_setting: 'any' // string, optional, default: 'any' - 'any', 'one_of', or 'not_one_of'
        }
    )

この例では、毎日午前 9 時にフローを開始します。

    // ✅ CORRECT - Daily trigger at specific time
    wfa.trigger(
        trigger.scheduled.daily,
        { 
            $id: Now.ID['daily_report_trigger'],
            annotation: 'Runs daily at 9 AM'
        },
        {
            time: Time({ hours: 9, minutes: 0, seconds: 0 })
        }
    )

この例では、インシデントレコードへのメール返信がある場合にフローを開始します。

    // Trigger when email arrives for incident table
    wfa.trigger(
        trigger.application.inboundEmail, // TriggerDefinition - inbound email event
        { 
            $id: Now.ID['incident_email_trigger'], // string | guid, mandatory
            annotation: 'Process emails for incident table' // string, optional
        },
        {
            target_table: 'incident', // string, optional - table for email replies/forwards
            email_conditions: '', // string, optional - filter which emails trigger the flow
            order: 100, // number, optional - execution order when multiple email triggers exist
            stop_condition_evaluation: true // boolean, optional - stop evaluating other triggers if this one matches
        }
    )

    // Access email data in flow body:
    (_params) => {
        const emailSubject = _params.trigger.email.subject // Email subject
        const emailBody = _params.trigger.email.body // Email body
        const emailFrom = _params.trigger.email.from // Sender email address
    }

この例では、 サービスカタログ アイテムが要求されたときにフローを開始します。この例では、フローを実行するように サービスカタログ アイテムを構成していることを前提としています。

    import { Flow, wfa, trigger, action } from "@servicenow/sdk/automation";

    Flow(
      {
        $id: Now.ID["laptop_fulfillment"],
        name: "Laptop Fulfillment Workflow"
      },

      wfa.trigger(
        trigger.application.serviceCatalog,
        { $id: Now.ID["catalog_trigger"] },
        {
          run_flow_in: "background"
        }
      ),

      _params => {
        // Log the catalog request
        wfa.action(
          action.core.log,
          { $id: Now.ID["log_request"] },
          {
            log_level: "info",
            log_message: `Processing catalog request: ${wfa.dataPill(_params.trigger.request_item, "string")}`
          }
        );

        // Create fulfillment task
        wfa.action(
          action.core.createCatalogTask,
          { $id: Now.ID["create_task"] },
          {
            ah_requested_item: wfa.dataPill(
              _params.trigger.request_item,
              "reference"
            ),
            ah_short_description: "Fulfill laptop request",
            ah_fields: TemplateValue({
              assignment_group: "Hardware Fulfillment Team",
              priority: "3"
            })
          }
        );
      }
    );

## wfa.action 関数 {#fluent-wfa-action-function__fluent-object-title}

フローまたはサブフローから特定のアクションインスタンスを実行します。アクションは、どのデータが生成、更新、または取得されるかを決定します。
フローまたはサブフローオブジェクトのFlow Body関数にwfa.action関数を追加します。  
次のタイプのアクションインスタンスがサポートされています。

* action.core.createRecord
* action.core.createOrUpdateRecord
* action.core.deleteRecord
* action.core.lookUpRecord
* action.core.lookUpRecords
* action.core.updateRecord
* action.core.updateMultipleRecords
* action.core.sendNotification
* action.core.sendEmail
* action.core.sendSms
* action.core.askForApproval
* action.core.waitForApproval
* action.core.createTask
* action.core.createCatalogTask
* action.core.submitCatalogItemRequest
* action.core.getCatalogVariables
* action.core.recordProducer
* action.core.log
* action.core.waitForCondition
* action.core.waitForMessage
* action.core.slaPercentageTimer
{#fluent-wfa-action-function__ul_gjm_hlj_c3c}.

使用可能なアクションの詳細については、「 [Workflow Studio actions](https://www.servicenow.com/docs/access?context=flow-actions&version=brazil&pubname=brazil-build-workflows&ft:locale=en-US)」を参照してください。
{#fluent-wfa-action-function__table_zyb_kqj_xhc__entry__3}{#fluent-wfa-action-function__now-id-desc2}

| 名前 | タイプ | 説明 |
|-|-|-|
| アクション | 文字列 | 実行する特定のアクションの名前。すべてのアクション名には、 `action.core` で始まるドット表記が使用されます。たとえば、 `action.core.lookUpRecord`、 `action.core.lookUpRecords`、 `action.core.createRecord`、 `action.core.updateRecord` などです。 |
| 構成 | オブジェクト | 必須。Fluent オブジェクトまたは関数のメタデータ構成プロパティを含むオブジェクト。 |
| $id | 文字列または数値 | 必須。メタデータオブジェクトの一意の ID。アプリケーションをビルドすると、この ID は一意のsys_idにハッシュされます。詳細については、「[ServiceNow Fluent 言語構成](https://servicenow-prod.fluidtopics.net/dSv2_sKS5nR8QxKtIHLmPQ "ServiceNow Fluent 言語構成は、 ServiceNow Fluent API を使用してソースコードで開発するための追加機能を提供します。")」を参照してください。 形式: `Now.ID['string' or number]` |
| 入力 | オブジェクト | `table_name`や`値`など、アクションに必要な入力パラメーターを含むオブジェクト。 |
[表 : 4. プロパティ]

{#fluent-wfa-action-function__table_zyb_kqj_xhc}  
この例は、変更要求が承認され、要求者に通知されたときに実行されます。このフローでは、\[レコードの検索\]、\[メールの送信\]、および \[レコードの更新\] アクションを使用します。

    import { action, Flow, wfa, trigger } from '@servicenow/sdk/automation'

    export const changeRequestApprovalNotificationFlow = Flow(
        {
            $id: Now.ID['change_request_approval_notification_flow'],
            name: 'Change Request Approval Notification Flow',
            description: 'Sends formatted notification to requester when change request is approved',
        },
        wfa.trigger(
            trigger.record.updated,
            { $id: Now.ID['change_request_approved_trigger'] },
            {
                table: 'change_request',
                condition: 'approval=approved',
                run_flow_in: 'background',
                trigger_strategy: 'unique_changes',
                run_when_user_list: [],
                run_when_setting: 'both',
                run_on_extended: 'false',
                run_when_user_setting: 'any',
            }
        ),
        (params) => {
            const requester = wfa.action(
                action.core.lookUpRecord,
                { $id: Now.ID['lookup_requester_details'] },
                {
                    table: 'sys_user',
                    conditions: `sys_id=${wfa.dataPill(params.trigger.current.requested_by, 'reference')}`,
                    sort_type: 'sort_asc',
                    if_multiple_records_are_found_action: 'use_first_record',
                }
            )

            wfa.action(
                action.core.sendEmail,
                { $id: Now.ID['send_approval_notification_email'] },
                {
                    table_name: 'change_request',
                    watermark_email: true,
                    ah_subject: `Change Request ${wfa.dataPill(params.trigger.current.number, 'string')} - Approved`,
                    ah_body: `Your change request has been approved.`,
                    record: wfa.dataPill(params.trigger.current.sys_id, 'reference'),
                    ah_to: wfa.dataPill(requester.Record.email, 'string'),
                }
            )

            wfa.action(
                action.core.updateRecord,
                { $id: Now.ID['update_work_notes_notification_sent'] },
                {
                    table_name: 'change_request',
                    record: wfa.dataPill(params.trigger.current.sys_id, 'reference'),
                    values: TemplateValue({
                        work_notes: `Approval notification sent to ${wfa.dataPill(requester.Record.name, 'string')} (${wfa.dataPill(requester.Record.email, 'string')})`,
                    }),
                }
            )
        }
    )

この例では、変更要求レコードが高影響度として作成または更新されたときにフローを実行します。このフローでは、変更要求を高リスクとしてマークする \[レコードの更新\]、\[CAB という名前のグループを検索するレコードの検索\]、\[高リスクの変更通知を CAB グループに送信する 通知の送信\]、およびレコードの更新と送信された通知の両方を文書化する \[ログ\] アクションを実行します。

    import { action, Flow, wfa, trigger } from '@servicenow/sdk/automation'

    export const changeRiskTaggingFlow = Flow(
        {
            $id: Now.ID['change_risk_tagging_flow'],
            name: 'Change Risk Tagging Flow',
            description: 'Tags change requests with high-risk label when created or updated with high impact',
        },
        wfa.trigger(
            trigger.record.createdOrUpdated,
            { $id: Now.ID['change_risk_trigger'] },
            {
                table: 'change_request',
                condition: 'active=true^impact=1',
                run_flow_in: 'background',
                run_on_extended: 'false',
                run_when_setting: 'both',
                run_when_user_setting: 'any',
                run_when_user_list: [],
            }
        ),
        (params) => {
            wfa.action(
                action.core.updateRecord,
                { $id: Now.ID['tag_high_risk'] },
                {
                    table_name: 'change_request',
                    record: wfa.dataPill(params.trigger.current.sys_id, 'reference'),
                    values: TemplateValue({
                        risk: 'high',
                        work_notes: 'Automatically tagged as high-risk due to high impact.',
                    }),
                }
            )

            const cab = wfa.action(
                action.core.lookUpRecord,
                { $id: Now.ID['lookup_cab_group'] },
                {
                    table: 'sys_user_group',
                    conditions: 'name=CAB^active=true',
                    sort_type: 'sort_asc',
                    if_multiple_records_are_found_action: 'use_first_record',
                }
            )

            wfa.action(
                action.core.sendNotification,
                { $id: Now.ID['notify_cab_high_risk'] },
                {
                    table_name: 'change_request',
                    record: wfa.dataPill(params.trigger.current.sys_id, 'reference'),
                    notification: 'high_risk_change_cab_notification',
                }
            )

            wfa.action(
                action.core.log,
                { $id: Now.ID['log_risk_tagged'] },
                {
                    log_level: 'warn',
                    log_message: `Change ${wfa.dataPill(params.trigger.current.number, 'string')} tagged as high-risk. CAB group ${wfa.dataPill(cab.Record.name, 'string')} notified.`,
                }
            )
        }
    )

## wfa.flow_logic 関数 {#fluent-wfa-flow_logic-function__fluent-object-title}

フローまたはサブフローから特定のフローロジックインスタンスを実行します。フローロジックは、データを使用するタイミングと方法を決定します。
フローまたはサブフローオブジェクトのFlow Body関数にwfa.flow_logic関数を追加します。  
次のタイプのフローロジックインスタンスがサポートされています。

* if
* elseIf
* else
* forEach
* waitForADuration
* exitLoop、 endFlow、 skipIteration、 setFlowVariables、 assignSubflowOutputs
{#fluent-wfa-flow_logic-function__ul_flf_tlj_c3c}.

使用可能なフローロジックの詳細については、「 [Workflow Studio flow logic](https://www.servicenow.com/docs/access?context=flow-logic&version=brazil&pubname=brazil-build-workflows&ft:locale=en-US)」を参照してください。
{#fluent-wfa-flow_logic-function__table_nbq_m5j_xhc__entry__3}{#fluent-wfa-flow_logic-function__now-id-desc2}

| 名前 | タイプ | 説明 |
|-|-|-|
| 構成 | オブジェクト | 必須。Fluent オブジェクトまたは関数のメタデータ構成プロパティを含むオブジェクト。 |
| $id | 文字列または数値 | 必須。メタデータオブジェクトの一意の ID。アプリケーションをビルドすると、この ID は一意のsys_idにハッシュされます。詳細については、「[ServiceNow Fluent 言語構成](https://servicenow-prod.fluidtopics.net/dSv2_sKS5nR8QxKtIHLmPQ "ServiceNow Fluent 言語構成は、 ServiceNow Fluent API を使用してソースコードで開発するための追加機能を提供します。")」を参照してください。 形式: `Now.ID['string' or number]` |
| 注釈 | 文字列 | このフローロジックのインスタンスが何を実行するかを説明します。たとえば、「 `Priority is critical」という注釈`などです。 |
| ステータス | 文字列 | wfa.flow_logic.if 関数および wfa.flow_logic.elseIf 関数で必須です。このフローロジックを実行するために true である必要があるデータ値。たとえば、 `condition: '\${_params.trigger.current.priority}=1',`. |
| item | アレイ | wfa.flow_logic.forEach 関数で必須です。反復処理するレコードのアレイまたはコレクション。通常、このレコードリストは、アクション.core.lookUpRecordsアクションへのwfa.action関数呼び出しから動的に生成されます。たとえば、 `問題などです。レコード` アレイは、 action.core.lookUpRecords アクションから生成できます。 (_params) => { //Find all the newly created problem records for the past day const problems = wfa.action( action.core.lookUpRecords, { $id: Now.ID['daily_unassigned_new_problems_triage_flow_step1'], annotation: 'Find all the newly created problem records for the past day', }, { table: 'problem', conditions: 'sys_created_onONYesterday@javascript:gs.beginningOfYesterday()@javascript:gs.endOfYesterday()', } ) //Iterate over the problems wfa.flow_logic.forEach( problems.Records, { ... } |
| ラベル | 文字列 | フローロジックのこのインスタンスを説明する値を表示します。たとえば、 `label: 'If Priority is critical'`,。 |
| 変数 | スキーマ | wfa.flow_logic.assignSubflowOutputs 関数および wfa.flow_logic.setFlowVariables 関数で必須です。フロー変数のデータ構造を定義する FlowVariables API によって生成されるスキーマ。たとえば、 `flowVars` スキーマは FlowVariables から生成できます。 import { FlowVariables } from '@servicenow/sdk/automation' // Define flow variables const flowVars = FlowVariables({ status: StringColumn({ label: 'Status' }), count: IntegerColumn({ label: 'Count' }), isActive: BooleanColumn({ label: 'Is Active' }), }) // Flow body (_params) => { // Set flow variables with literal values wfa.flow_logic.setFlowVariables( { $id: Now.ID['initialize_variables'], annotation: 'Initialize flow variables with default values', }, _params.flowVariables, { ... } 重要: このプロパティの引数としては常に `_params.flowVariables` を使用します。間違ったスキーマを渡すと、検証エラーが発生します。 |
| フローロジック本体 | 関数 | Flow logic body は、フローロジックの実行ステップを表す TypeScript の Arrow function です。フロー本体は、wfa.trigger オブジェクトと flowVariables オブジェクトを含む _params パラメーターを入力として受け取ります。Flow logic bodyのステップは、次の関数呼び出しで構成されます。 * wfa.action 関数: フローまたはサブフローから特定のアクションインスタンスを実行します。アクションは、どのデータが生成、更新、または取得されるかを決定します。。wfa.action関数の詳細については、「[wfa.action 関数](https://servicenow-prod.fluidtopics.net/y34uNCkew6iimGPgrKlGpA#fluent-wfa-action-function "フローまたはサブフローから特定のアクションインスタンスを実行します。アクションは、どのデータが生成、更新、または取得されるかを決定します。")」を参照してください。 * wfa.flow_logic 関数: フローまたはサブフローから特定のフローロジックインスタンスを実行します。フローロジックは、データを使用するタイミングと方法を決定します。 wfa.flow_logic関数の詳細については、「 [wfa.flow_logic 関数](https://servicenow-prod.fluidtopics.net/y34uNCkew6iimGPgrKlGpA#fluent-wfa-flow_logic-function "フローまたはサブフローから特定のフローロジックインスタンスを実行します。フローロジックは、データを使用するタイミングと方法を決定します。")」を参照してください。 {#fluent-wfa-flow_logic-function__ul_nmd_wc4_rhc} |
[表 : 5. プロパティ]

{#fluent-wfa-flow_logic-function__table_nbq_m5j_xhc}  
この例は、トリガーレコードの条件をチェックしている様子を示しています。現在のレコードの優先度が 1 の場合、レコードは優先度が「重大」チームにアサインされます。それ以外の場合、現在のレコードの優先度の値が 2 の場合、レコードは優先度の高いチームにアサインされます。どちらの条件も満たされない場合、レコードは一般チームにアサインされます。

    // Flow body showing if/elseIf/else usage
    (_params) => {
        wfa.flow_logic.if(
            {
                $id: Now.ID['check_critical_priority'],
                condition: `\${_params.trigger.current.priority}=1`,
                annotation: 'Priority is critical',
            },
            () => {
                wfa.action(
                    action.core.updateRecord,
                    { $id: Now.ID['assign_critical_team'], annotation: 'Assign to critical team' },
                    { record: _params.trigger.current, table_name: 'incident', values: 'assignment_group=critical_team' }
                )
            }
        )
        wfa.flow_logic.elseIf(
            { $id: Now.ID['check_high_priority'], condition: `\${_params.trigger.current.priority}=2`, annotation: 'Priority is high' },
            () => {
                wfa.action(
                    action.core.updateRecord,
                    { $id: Now.ID['assign_high_team'], annotation: 'Assign to high team' },
                    { record: _params.trigger.current, table_name: 'incident', values: 'assignment_group=high_team' }
                )
            }
        )
        wfa.flow_logic.else(
            { $id: Now.ID['assign_default'], annotation: 'Default assignment' },
            () => {
                wfa.action(
                    action.core.updateRecord,
                    { $id: Now.ID['assign_general_team'], annotation: 'Assign to general team' },
                    { record: _params.trigger.current, table_name: 'incident', values: 'assignment_group=general_team' }
                )
            }
        )
    }

この例では、問題レコードのリストを反復処理して未アサインのレコードを見つけ、それらを問題トリアージグループにアサインして、そのグループにメールを送信します。

    // Flow body showing forEach usage with lookUpRecords
    (_params) => {
        //Find all the newly created problem records for the past day
        const problems = wfa.action(
            action.core.lookUpRecords,
            {
                $id: Now.ID['daily_unassigned_new_problems_triage_flow_step1'],
                annotation: 'Find all the newly created problem records for the past day',
            },
            {
                table: 'problem',
                conditions:
                    'sys_created_onONYesterday@javascript:gs.beginningOfYesterday()@javascript:gs.endOfYesterday()',
            }
        )

        //Iterate over the problems
        wfa.flow_logic.forEach(
            problems.Records,
            { $id: Now.ID['daily_unassigned_new_problems_triage_flow_step2'], annotation: 'Iterate each problem' },
            (item) => {
                //Check if the problem is not assigned
                wfa.flow_logic.if(
                    {
                        $id: Now.ID['daily_unassigned_new_problems_triage_flow_step3'],
                        condition: `\${item.assignment_group}ISEMPTY`,
                        annotation: 'Check if problem is not assigned',
                    },
                    () => {
                        wfa.action(
                            action.core.updateRecord,
                            {
                                $id: Now.ID['daily_unassigned_new_problems_triage_flow_step4'],
                                annotation: 'Update the problem record state',
                            },
                            { table_name: 'problem', record: item, values: 'state=1' }
                        )

                        //Send notification to the group
                        wfa.action(
                            action.core.sendNotification,
                            {
                                $id: Now.ID['daily_unassigned_new_problems_triage_flow_step5'],
                                annotation: 'Send notification to the group',
                            },
                            {
                                table_name: 'problem',
                                record: item,
                                notification: '',
                            }
                        )
                    }
                )
            }
        )
    }

この例では、フロー変数をデータピルに格納されている動的な値に設定します。

    import { FlowVariables } from '@servicenow/sdk/automation'

    const flowVars = FlowVariables({
        incidentPriority: IntegerColumn({ label: 'Incident Priority' }),
        assignedGroup: StringColumn({ label: 'Assigned Group' }),
        threshold: IntegerColumn({ label: 'Threshold' }),
        actionResult: StringColumn({ label: 'Action Result' }),
    })

    (_params) => {
        // Lookup action result
        const lookupResult = wfa.action(
            action.core.lookUpRecord,
            { $id: Now.ID['lookup_config'], annotation: 'Get configuration' },
            { table: 'sys_properties', conditions: 'name=incident.threshold' }
        )

        // Set flow variables using datapills from trigger, action outputs, and other flow variables
        wfa.flow_logic.setFlowVariables(
            {
                $id: Now.ID['set_variables_with_datapills'],
                annotation: 'Set variables from trigger and action outputs',
            },
            _params.flowVariables,
            {
                incidentPriority: _params.trigger.current.priority,        // Trigger datapill
                assignedGroup: _params.trigger.current.assignment_group,   // Trigger datapill
                threshold: lookupResult.Record.value,                      // Action output datapill
                actionResult: _params.flowVariables.status,                // Flow variable datapill
            }
        )
    }

この例では、フロー変数を使用してサブフロー出力をアサインします。

    // Flow body showing assignSubflowOutputs usage with flow variables
    import { FlowVariables } from '@servicenow/sdk/automation'

    const flowVars = FlowVariables({
        userEmail: StringColumn({ label: 'User Email' }),
        userName: StringColumn({ label: 'User Name' }),
        isApproved: BooleanColumn({ label: 'Is Approved' }),
    })

    (_params) => {
        // Call a subflow that returns user information
        const subflowResult = wfa.subflow(
            userInfoSubflow,
            { $id: Now.ID['get_user_info'], annotation: 'Get user information' },
            { userId: _params.trigger.current.caller_id }
        )

        // Assign subflow outputs to flow variables in one operation
        wfa.flow_logic.assignSubflowOutputs(
            { $id: Now.ID['assign_outputs'], annotation: 'Assign user info to flow variables' },
            flowVars,
            {
                userEmail: subflowResult.email,
                userName: subflowResult.name,
                isApproved: subflowResult.approved,
            }
        )

        // Now flow variables can be used throughout the flow
        // Access via _params.flowVariables.userEmail, etc.
    }

## wfa.dataPill 関数 {#fluent-wfa-dataPill-function__fluent-object-title}

アクションまたはフローロジック入力から特定のランタイムデータピル値を参照します。
wfa.dataPill関数をアクションまたはflow_logic関数の入力パラメータに追加します。使用するデータピルごとに定数を定義します。通常、この定数はwfa.actionまたはwfa.flow_logic関数の出力を格納します。
{#fluent-wfa-dataPill-function__table_lhb_y5m_k3c__entry__3}{#fluent-wfa-dataPill-function__fluent-object-entry}

| 名前 | タイプ | 説明 |
|-|-|-|
| expression | 文字列 | 必須。入力値として使用するランタイムデータへのドット表記の参照。一般的に使用されるランタイム値には、トリガーデータ、アクション出力、サブフロー出力などがあります。 トリガーレコードデータ :   トリガーレコードのフィールド値。たとえば、 _params.trigger.current.fieldName です。 トリガーレコードテーブル :   トリガーレコードのテーブル名。たとえば、 _params.trigger.table_name です。 アクションの出力値 :   以前に実行されたアクションからの出力値。例: actionResult.fieldName サブフロー出力値 :   以前に実行されたサブフローからの出力値。例: subflowResult.fieldName |
| タイプ | 文字列 | 必須。文字列、ブーリアン、整数、参照などのデータのデータ型。使用可能なフィールドデータタイプのリストについては、「 [Field types reference](https://www.servicenow.com/docs/access?context=r_FieldTypes&version=brazil&pubname=brazil-platform-administration&ft:locale=en-US)」を参照してください。 |
[表 : 6. プロパティ]

{#fluent-wfa-dataPill-function__table_lhb_y5m_k3c}  
この例では、バインドされていないメールレコードを使用して、受信メールの値に基づいてインシデントまたはタスクを作成します。この例では、params オブジェクトを使用してトリガー内のデータを参照します。この例では、定数sender、senderManager、p3Incident、およびattachmentsも定義して、後のwfa.dataPill関数で使用するアクションとフローロジックの出力を格納します。

    import { action, Flow, wfa, trigger } from '@servicenow/sdk/automation'

    export const emailIncidentTaskFlow = Flow(
        {
            $id: Now.ID['email_incident_task_flow'],
            name: 'Email Incident/Task Creation Flow',
            description: 'Creates incidents or tasks based on email content with "raise incident or task" in subject',
        },
        wfa.trigger(
            trigger.application.inboundEmail,
            { $id: Now.ID['inbound_email_trigger'] },
            {
                email_conditions: 'subjectLIKEraise incident or task',
                target_table: 'incident',
            }
        ),
        (params) => {
            wfa.action(
                action.core.log,
                { $id: Now.ID['log_email_received'] },
                {
                    log_level: 'info',
                    log_message: `Email received from: ${wfa.dataPill(params.trigger.from_address, 'string')}, Subject: ${wfa.dataPill(params.trigger.subject, 'string')}`,
                }
            )

            const sender = wfa.action(
                action.core.lookUpRecord,
                { $id: Now.ID['lookup_sender'] },
                {
                    table: 'sys_user',
                    conditions: `email=${wfa.dataPill(params.trigger.from_address, 'string')}`,
                    sort_type: 'sort_asc',
                    if_multiple_records_are_found_action: 'use_first_record',
                }
            )

            // Internal P1 path --- two tasks
            wfa.flowLogic.if(
                {
                    $id: Now.ID['check_internal_p1'],
                    condition: `${wfa.dataPill(sender.Record.email, 'string')}LIKEservicenow^${wfa.dataPill(params.trigger.subject, 'string')}LIKEP1`,
                    annotation: 'Internal sender with P1 subject',
                },
                () => {
                    const senderManager = wfa.action(
                        action.core.lookUpRecord,
                        { $id: Now.ID['lookup_sender_manager'] },
                        {
                            table: 'sys_user',
                            conditions: `sys_id=${wfa.dataPill(sender.Record.manager, 'reference')}`,
                            sort_type: 'sort_asc',
                            if_multiple_records_are_found_action: 'use_first_record',
                        }
                    )

                    wfa.action(
                        action.core.createTask,
                        { $id: Now.ID['task_for_manager'] },
                        {
                            task_table: 'incident',
                            field_values: TemplateValue({
                                priority: 1,
                                assigned_to: wfa.dataPill(senderManager.Record.sys_id, 'reference'),
                                short_description: wfa.dataPill(params.trigger.inbound_email.body, 'reference'),
                                urgency: 1,
                                impact: 1,
                            }),
                        }
                    )

                    wfa.action(
                        action.core.createTask,
                        { $id: Now.ID['task_for_sender'] },
                        {
                            task_table: 'incident',
                            field_values: TemplateValue({
                                priority: 1,
                                assigned_to: wfa.dataPill(sender.Record.sys_id, 'reference'),
                                short_description: wfa.dataPill(params.trigger.subject, 'string'),
                                urgency: 1,
                                impact: 1,
                            }),
                        }
                    )
                }
            )

            // External / non-P1 path --- P3 incident + copy attachments
            wfa.flowLogic.else({ $id: Now.ID['create_p3_incident_branch'] }, () => {
                const p3Incident = wfa.action(
                    action.core.createRecord,
                    { $id: Now.ID['create_p3_incident'] },
                    {
                        table_name: 'incident',
                        values: TemplateValue({
                            priority: 4,
                            short_description: wfa.dataPill(params.trigger.subject, 'string'),
                            description: `From: ${wfa.dataPill(params.trigger.from_address, 'string')}\n\n${wfa.dataPill(params.trigger.inbound_email.body, 'reference')}`,
                            contact_type: 'email',
                            caller_id: wfa.dataPill(sender.Record.sys_id, 'reference'),
                        }),
                    }
                )

                const attachments = wfa.action(
                    action.core.getAttachmentsOnRecord,
                    { $id: Now.ID['get_email_attachments'] },
                    { source_record: wfa.dataPill(params.trigger.inbound_email.sys_id, 'reference') }
                )

                wfa.flowLogic.forEach(
                    wfa.dataPill(attachments.parameter, 'records'),
                    { $id: Now.ID['copy_attachments_loop'] },
                    () => {
                        wfa.action(
                            action.core.copyAttachment,
                            { $id: Now.ID['copy_attachment'] },
                            {
                                target_record: wfa.dataPill(p3Incident.record, 'reference'),
                                attachment_record: wfa.dataPill(attachments.parameter, 'records'),
                                table: 'incident',
                            }
                        )
                    }
                )

                wfa.action(
                    action.core.sendEmail,
                    { $id: Now.ID['confirm_p3_email'] },
                    {
                        table_name: 'incident',
                        ah_to: wfa.dataPill(params.trigger.from_address, 'string'),
                        ah_subject: `Incident Created: ${wfa.dataPill(params.trigger.subject, 'string')}`,
                        ah_body: `Your request has been received and a P3 incident has been created. Our team will be in touch shortly.`,
                        record: wfa.dataPill(p3Incident.record, 'reference'),
                    }
                )
            })
        }
    )

## wfa.subflow 関数 {#fluent-wfa-subflow-function__fluent-object-title}

親フローまたはサブフローから特定のサブフローを実行します。
再利用可能な一連のアクションとフローロジックを実行するサブフローオブジェクトを作成します。サブフローオブジェクトを作成するには、「 [サブフローオブジェクト](https://servicenow-prod.fluidtopics.net/y34uNCkew6iimGPgrKlGpA#fluent-subflow-object "サブフロー [sys_hub_flow] を作成して、フローまたは API によって呼び出されたときに、再利用可能な一連のアクションとフローロジックを実行します。")」を参照してください。

フローまたはサブフローオブジェクトのFlow Body関数にwfa.subflow関数を追加して、特定のサブフローを呼び出します。
{#fluent-wfa-subflow-function__table_ozs_2mk_xhc__entry__3}{#fluent-wfa-subflow-function__now-id-desc2}

| 名前 | タイプ | 説明 |
|-|-|-|
| サブフロー | 文字列 | 実行する特定のサブフローの名前。すべてのサブフロー名は、 `action.core` で始まるドット表記を使用します。たとえば、 `action.core.lookUpRecord`、 `action.core.lookUpRecords`、 `action.core.createRecord`、 `action.core.updateRecord` などです。 |
| 構成 | オブジェクト | 必須。Fluent オブジェクトまたは関数のメタデータ構成プロパティを含むオブジェクト。 |
| $id | 文字列または数値 | 必須。メタデータオブジェクトの一意の ID。アプリケーションをビルドすると、この ID は一意のsys_idにハッシュされます。詳細については、「[ServiceNow Fluent 言語構成](https://servicenow-prod.fluidtopics.net/dSv2_sKS5nR8QxKtIHLmPQ "ServiceNow Fluent 言語構成は、 ServiceNow Fluent API を使用してソースコードで開発するための追加機能を提供します。")」を参照してください。 形式: `Now.ID['string' or number]` |
| 注釈 | 文字列 | エディターに表示するサブフローのテキスト説明。 |
| 入力 | オブジェクト | サブフローに必要なサブフロー入力パラメーター ( `件名` や `本文`など) を含むオブジェクト。 |
| 完了待ち | ブーリアン | サブフローの実行が完了するまで、親呼び出し元フローまたはサブフローを一時停止するオプション。 有効な値:true、false デフォルト値：false |
[表 : 7. プロパティ]

{#fluent-wfa-subflow-function__table_ozs_2mk_xhc}  
この例では、定数名 notifyUserSubflow で呼び出すことができるサブフローオブジェクトを作成します。

    // File: fluent/flows/notify-user-subflow.now.ts
    import { Subflow, wfa, action } from "@servicenow/sdk/automation";
    import { StringColumn, BooleanColumn } from "@servicenow/sdk/core";

    export const notifyUserSubflow = Subflow(
      {
        $id: Now.ID["notify_user_subflow"],
        name: "Notify User Subflow",
        runAs: "system",
        inputs: {
          userId: StringColumn({ label: "User Sys ID", mandatory: true }),
          message: StringColumn({ label: "Message", mandatory: true })
        },
        outputs: {
          notified: BooleanColumn({ label: "Notified", mandatory: true })
        }
      },
      params => {
        wfa.action(
          action.core.log,
          { $id: Now.ID["log_notify"], annotation: "Log notification" },
          {
            log_level: "info",
            log_message: `Notifying user: ${wfa.dataPill(params.inputs.userId, "string")} --- ${wfa.dataPill(params.inputs.message, "string")}`
          }
        );

        wfa.flowLogic.assignSubflowOutputs(
          { $id: Now.ID["assign_notify_outputs"] },
          params.outputs,
          { notified: true }
        );
      }
    );

この例では、前の Subflow オブジェクトによって作成された notifyUserSubflow サブフローを呼び出します。

    // File: fluent/flows/incident-created-flow.now.ts
    import { Flow, wfa, trigger, action } from "@servicenow/sdk/automation";
    import { notifyUserSubflow } from "./notify-user-subflow.now";

    Flow(
      {
        $id: Now.ID["incident_created_flow"],
        name: "Incident Created Flow",
        runAs: "system"
      },
      wfa.trigger(
        trigger.record.created,
        { $id: Now.ID["trg_incident_created"] },
        {
          table: "incident",
          condition: "priority=1",
          run_flow_in: "background",
          run_on_extended: "false",
          run_when_user_list: [],
          run_when_setting: "both",
          run_when_user_setting: "any"
        }
      ),
      _params => {
        const result = wfa.subflow(
          notifyUserSubflow,
          {
            $id: Now.ID["notify_user_instance"],
            annotation: "Notify assigned user"
          },
          {
            userId: wfa.dataPill(
              _params.trigger.current.assigned_to.sys_id,
              "string"
            ),
            message: "A P1 incident has been assigned to you.",
            waitForCompletion: true
          }
        );

        wfa.action(
          action.core.log,
          { $id: Now.ID["log_notify_result"] },
          {
            log_level: "info",
            log_message: `Subflow notified: ${wfa.dataPill(result.notified, "boolean")}`
          }
        );
      }
    );


