---
sourceDocument: Yokohama Mobile 구성 및 탐색
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ko-KR/yokohama/mobile

 Release :

    - yokohama

ft:locale :

    - ko-KR

ft:publication_title :

    - Yokohama Mobile 구성 및 탐색

ft:clusterId :

    - mobile

bundleId :

    - mobile

workflow :

    - evelopment, Data and Analytics


---

# 데이터 소스 스크립트 예시

# 데이터 소스 스크립트 예시 {#ariaid-title1}

* 릴리스 버전: Yokohama
* 
* 업데이트 날짜 2025년 03월 05일
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 소요 시간: 11분

데이터 소스 스크립트를 사용하여 입력 값, 설명 요소 및 입력 작업을 매핑합니다. 또는 이러한 각 요소에 대한 전용 데이터 소스를 생성합니다.
데이터 소스 스크립트는 <var class="keyword varname">valuesMapper</var> 와 <var class="keyword varname">context</var>라는 두 가지 매개변수를 허용합니다. 컨텍스트 매개변수는 사용자가 상호작용하는 입력 양식을 나타냅니다. <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/dcb3C6u7GKi3MCip9wdK2Q "입력 양식 화면에서 데이터를 검색하고 표시할 수 있도록 요소 식별자를 사용하여 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">input_3_score</var><var class="keyword varname">점수</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">input_1_rich_text_descriptive_element_id rich_text_1_col</var> (HTML 유형) <var class="keyword varname"></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">input_1_image_descriptive_element_id</var>에 대한 <var class="keyword varname">image_1_col</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> 를 정의합니다. 다음 프로세스가 발생합니다.

* "인시던트" 테이블에 대한 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}

