---
sourceDocument: オーストラリアのモバイル構成とナビゲーション
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ja-JP/mobile

 Release :

    - australia

ft:locale :

    - ja-JP

ft:publication_title :

    - オーストラリアのモバイル構成とナビゲーション

ft:clusterId :

    - mobile

bundleId :

    - mobile

workflow :

    - Development, Data and Analytics


---

# データソーススクリプトの例

# データソーススクリプトの例 {#ariaid-title1}

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

データソーススクリプトを使用して、入力値、説明要素、および入力アクションをマッピングします。または、これらの要素ごとに専用のデータソースを作成します。
データソーススクリプトは、 <var class="keyword varname">valuesMapper</var> と <var class="keyword varname">context</var> の 2 つのパラメーターを受け取ります。コンテキストパラメーターは、ユーザーが操作している入力フォームを参照します。<var class="keyword varname">valuesMapper</var> パラメーターは、<var class="keyword varname">addRecordMapping</var> メソッドを介して要素識別子を特定のテーブル列にリンクする役割を果たします。たとえば、メソッド呼び出しは次のようになります。

    valuesMapper.addRecordMapping(UNIQUE_ELEMENT_IDENTIFIER, GLIDE_RECORD_INSTANCE, COLUMN_NAME);

注:  
このトピックに記載されているすべてのスクリプトは、データソースレコード内で構成されます。詳細については、「[データソースの構成](https://servicenow-prod.fluidtopics.net/GivAedMCLKjjTHT7NIO_TA "要素識別子を使用して UI 要素を特定のデータベースフィールドにマップするようにデータソースを構成し、データを取得して入力フォーム画面に表示できるようにします。このマッピングは、各 UI 要素がレコード内の対応するデータフィールドを正確に反映していることを確認します。")」を参照してください。

## デフォルトのサンプルスクリプト {#data-source-script-examples__section_g31_xvm_p2c}

モバイルアプリビルダー内で提供されるサンプルスクリプトは次のとおりです。このスクリプトは、既存のテーブルをフィルタリングする方法と、特定のフィールドを UI 要素にマップする方法を示すテンプレートを提供します。

    (function DataSource(valuesMapper, context) {
    var gr = new GlideRecord(TABLE_NAME); // Could be any table within the Instance, including custom tables
    gr.addQuery('sys_id',context.getUniqueValue());
    gr.query();
    if (gr.next()) { // Could also be itetaring muliple records from the same table using the 'while' iterator

        valuesMapper.addRecordMapping('short_description',gr,'short_description'); // Map the field short_description to a UI element that has element identifier of "short_description". The element identifier could be any String, it's easier to map the column's name as the element identifer.

        valuesMapper.addRecordMapping('priority',gr,'priority'); // Map the field priority to a UI element that has element identifier of "priority". The element identifier could be any String, it's easier to map the column's name as the element identifier.

    }
    })(valuesMapper, context);

このサンプルスクリプトには次のものが含まれます。

* データソースを定義する次のパラメーター:
  * <var class="keyword varname">valuesMapper</var>:このパラメーターは、データソースから UI 要素に値をマップするために使用されます。
  * <var class="keyword varname">コンテキスト</var>:このパラメーターは、インシデント、変更要求、その他のテーブルなど、データソースが使用されるコンテキストを指定します。
  {#data-source-script-examples__ul_mjx_cwm_p2c}
* <var class="keyword varname">addRecordMapping</var> メソッドはフィールドをマッピングするために使用され、次のパラメーターで構成されます。
  * 要素識別子:マッピングするフィールドに定義した一意の名前。この例では、これは `<簡単な説明>` と `<優先度>`です。
  * Glide レコード `<gr>`:カスタムテーブルを含む、インスタンス内の任意のテーブルを参照するために使用されます。
  * フィールド名:Glide レコード内のフィールドの名前です。この例では、これは `<簡単な説明>` と `<優先度>`です。  
    注:  
    一般的なガイドラインでは、コードの保守と理解を容易にするために、要素識別子にフィールド名と同じ名前を付けます。
  {#data-source-script-examples__ul_lcm_3wm_p2c}
{#data-source-script-examples__ul_wpq_bwm_p2c}

## 入力フォームで構成された入力をマッピングするスクリプト {#data-source-script-examples__section_cny_nwm_p2c}

次に、属性 \[sys_sg_input_attribute\] テーブルで構成された入力の <var class="keyword varname">ElementIdentifier</var> 属性の処理方法を示すスクリプト例を示します。このスクリプトには、 <var class="keyword varname">input_1</var>、 <var class="keyword varname">input_2</var>、 <var class="keyword varname">input_3</var>、 <var class="keyword varname">input_4</var>、 <var class="keyword varname">input_5</var> という名前の 5 つの入力があるインシデントテーブルの列に入力値をマッピングする例が含まれています。

    (function DataSource(valuesMapper, context) {
    var gr = new GlideRecord('incident');
    gr.addQuery('sys_id',context.getUniqueValue());
    gr.query();
    if (gr.next()) {
    // Map the column short_description from the incident table to the elementIdentifier "input_1_short_description".
    valuesMapper.addRecordMapping('input_1_short_description', gr,'short_description'); 

    // Map the column start_time from the incident table to the elementIdentifier "input_2_start_time".
    valuesMapper.addRecordMapping('input_2_start_time',gr,'start_time'); 

    // Map the column score from the incident table to the elementIdentifier "input_3_score".
    valuesMapper.addRecordMapping('input_3_score', gr,'score'); 

    // Map the column assigned_to from the incident table to the elementIdentifier "input_4_assigned_to".
    valuesMapper.addRecordMapping('input_4_assigned_to',gr,'assigned_to');

    // Map the attachment from the record in the incident table to the elementIdentifier "input_5_attachment_1" (The column name must be "sys_id").
    valuesMapper.addRecordMapping('input_5_attachment_1',gr,'sys_id');

     }
    })(valuesMapper, context);

このコードは、インシデント \[incident\] テーブルレコードの特定の列を対応する要素識別子にマップする関数 <var class="keyword varname">DataSource</var> を定義します。次のプロセスが発生します。

* インシデント \[incident\] テーブルの <var class="keyword varname">GlideRecord</var> オブジェクトを作成します。
* <var class="keyword varname">コンテキスト</var>の一意の値を使用して、特定の<var class="keyword varname">sys_id</var>を持つレコードのテーブルクエリを実行します。
* レコードが見つかると、次の列が相関する一意の要素識別子にマップされます。
  * <var class="keyword varname">short_description</var> から <var class="keyword varname">input_1_short_description</var>
  * <var class="keyword varname">start_time</var> から <var class="keyword varname">input_2_start_time</var>
  * スコア<var class="keyword varname">から</var><var class="keyword varname">input_3_score</var>
  * <var class="keyword varname">assigned_to</var> から <var class="keyword varname">input_4_assigned_to</var>
  * <var class="keyword varname">sys_id</var> から <var class="keyword varname">input_5_attachment_1</var>
  {#data-source-script-examples__ul_v3n_dxm_p2c}
{#data-source-script-examples__ul_bn5_zwm_p2c}

## 入力フォームの入力または入力セクションに関連付けられた説明要素をマップするスクリプト {#data-source-script-examples__section_u2s_hxm_p2c}

次のスクリプト例は、説明要素 \[ sys_sg_descriptive_element\] テーブルで構成された、説明要素の <var class="keyword varname">ElementIdentifier</var> 属性を処理する方法を示しています。

    (function DataSource (valuesMapper, context) {
    var gr = new GlideRecord('incident');
    gr.addQuery('sys_id',context.getUniqueValue());
    gr.query();
    if (gr.next()) {
    // Handle descriptive element of type Rich Text. Map to a column named "rich_text_1_col" in the incident table to the elementIdentifier "input_1_rich_text_descriptive_element_id". The col type in the "incident" should be "HTML"
    valuesMapper.addRecordMapping('input_1_rich_text_descriptive_element_id',gr,'rich_text_1_col'); 

    // Handle descriptive element of type Text. Map to a column named "plain_text_1_col" in the incident table to the elementIdentifier "input_1_text_descriptive_element_id". The col type in the "incident" should be "String"/"String (Full UTF-8)"
    valuesMapper.addRecordMapping('input_1_text_descriptive_element_id',gr,'plain_text_1_col'); 

    // Handle descriptive element of type Image. Map to a column named "image_1_col" in the incident table to the elementIdentifier "input_1_image_descriptive_element_id". The col type in the "incident" should be "Image"
    valuesMapper.addRecordMapping('input_1_image_descriptive_element_id',gr,'image_1_col'); 
    }
    })(valuesMapper, context);

このコードは、インシデント \[incident\] テーブルレコードの特定の列を対応する要素識別子にマップする関数 <var class="keyword varname">DataSource</var> を定義します。次のプロセスが発生します。

* インシデント \[incident\] テーブルの <var class="keyword varname">GlideRecord</var> オブジェクトを作成します。
* <var class="keyword varname">コンテキスト</var>の一意の値を使用して、特定の<var class="keyword varname">sys_id</var>を持つレコードのテーブルクエリを実行します。
* レコードが見つかると、次の列が相関する一意の要素識別子にマップされます。
  * <var class="keyword varname">rich_text_1_col</var> (HTML タイプ) から <var class="keyword varname">input_1_rich_text_descriptive_element_id </var>
  * <var class="keyword varname">input_1_text_descriptive_element_id</var>する<var class="keyword varname">plain_text_1_col </var>(文字列タイプ)
  * <var class="keyword varname">image_1_col</var> (イメージタイプ) から <var class="keyword varname">input_1_image_descriptive_element_id</var>
  {#data-source-script-examples__ul_y2x_vxm_p2c}
{#data-source-script-examples__ul_sbf_txm_p2c}

## 入力フォームの入力に関連付けられた入力アクションをマッピングするスクリプト {#data-source-script-examples__section_bjw_cym_p2c}

次のスクリプト例は、入力フォームアクション \[sys_sg_parameter_action\] テーブルで構成された入力アクションの <var class="keyword varname">ElementIdentifier</var> 属性を処理する方法を示しています。

    (function DataSource(valuesMapper, context) {
    var gr = new GlideRecord('incident');
    gr.addQuery('sys_id',context.getUniqueValue());
    gr.query();
    if (gr.next()) {
    // Handle an attachment type input action. Map the elementIdentifier "input_1_action_attachments" to a record in the incident table by specifying the sys_id as the column in the table.
    valuesMapper.addRecordMapping('input_1_action_attachments',gr,'sys_id'); 

    // Handle a comment type input action. Map the elementIdentifier "input_1_action_comment" to a column in the incident table where the comment is stored. In this example, the comment is stored in the //"comment_by_agent" column.
    valuesMapper.addRecordMapping('input_1_action_comment',gr,'comment_by_agent'); 

    //Handle a navigation type input action with a record context.
    Map the elementIdentifier "input_1_navigation" to a record in the incident table by specifying the sys_id as the column in the table.
    valuesMapper.addRecordMapping('input_1_navigation',gr,'sys_id'); 
    }
    })(valuesMapper, context);

このコードは、インシデント \[incident\] テーブルレコードの特定の列を対応する要素識別子にマップする関数 <var class="keyword varname">DataSource</var> を定義します。次のプロセスが発生します。

* 「incident」テーブルの GlideRecord オブジェクトを作成します。
* <var class="keyword varname">コンテキスト</var>の一意の値を使用して、特定の<var class="keyword varname">sys_id</var>を持つレコードのテーブルクエリを実行します。
* レコードが見つかると、次の列が相関する一意の要素識別子にマップされます。
  * 添付ファイルタイプの入力アクションを処理するために<var class="keyword varname">input_1_action_attachments</var>する<var class="keyword varname">sys_id</var>。
  * コメントタイプの入力アクションを処理するために<var class="keyword varname">input_1_action_comment</var>する<var class="keyword varname">comment_by_agent</var>。
  * レコードコンテキストを使用してナビゲーションタイプの入力アクションを処理するために<var class="keyword varname">input_1_navigation</var>する<var class="keyword varname">sys_id</var>。
  {#data-source-script-examples__ul_qvf_mzm_p2c}
{#data-source-script-examples__ul_dwj_kzm_p2c}

