---
sourceDocument: Yokohama Mobile Configuration and Navigation
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/yokohama/mobile

 Release :

    - yokohama

ft:locale :

    - en-US

ft:publication_title :

    - Yokohama Mobile Configuration and Navigation

ft:clusterId :

    - mobile

bundleId :

    - mobile

workflow :

    - evelopment, Data and Analytics


---

# Data source script examples

# Data source script examples {#ariaid-title1}

Release version: Yokohama  
Updated March 5, 2025  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 5 minutes to read
Summarize  
![AI sparkle icon](https://servicenow.com/docs/portal-asset/ai-sparkle-icon) Summarized using AI  
This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.  

## Summary of Data Source Script Examples

Data source scripts in ServiceNow enable you to map input values, descriptive elements, and input actions from database records to UI elements within input forms.
These scripts accept two parameters:
Show full answer Show less  
* **valuesMapper:** Facilitates linking element identifiers to specific table columns using the `addRecordMapping` method.
* **context:** Refers to the input form context, providing the unique identifier of the record being interacted with.

Using these scripts, you can dynamically populate UI elements based on data from various tables, including custom ones.

## Key Features

* **Default Sample Script:** Demonstrates querying a table using a unique sysid and mapping fields like `shortdescription` and `priority` to UI elements.
* **Mapping Inputs:** Shows how to map configured inputs in the form to incident table columns by matching element identifiers (e.g., `input1shortdescription`) to their corresponding data fields (e.g., `shortdescription`).
* **Mapping Descriptive Elements:** Illustrates mapping descriptive elements such as rich text, plain text, and images by linking element identifiers to specific columns in the incident table with appropriate data types.
* **Mapping Input Actions:** Covers mapping input actions like attachments, comments, and navigation actions by associating element identifiers with relevant incident table columns (e.g., `sysid`, `commentbyagent`).

Each script follows a pattern of creating a `GlideRecord`, querying based on the unique context value, and then mapping fields to UI elements using `addRecordMapping`.

## Practical Use for ServiceNow Customers

By leveraging these data source scripts, you can:

* Customize how form inputs and descriptive elements display data dynamically from ServiceNow records.
* Maintain clear and maintainable mappings by aligning element identifiers with field names.
* Handle various input types and actions within mobile or web forms, ensuring data consistency and user-friendly interfaces.

This approach allows you to create rich, data-driven forms that reflect the underlying records accurately, improving the user experience and data integrity in your ServiceNow instance.  
Use data source scripts to map input values, descriptive elements, and input actions. Alternatively create a dedicated data source for each of these elements.
The data source script accepts two parameters: <var class="keyword varname">valuesMapper</var> and <var class="keyword varname">context</var>. The context parameter refers to the input form that the user is interacting with. The <var class="keyword varname">valuesMapper</var> parameter is responsible for linking element identifiers to specific table columns via the <var class="keyword varname">addRecordMapping</var> method. For example, the method call could look like this:

    valuesMapper.addRecordMapping(UNIQUE_ELEMENT_IDENTIFIER, GLIDE_RECORD_INSTANCE, COLUMN_NAME);

Note:  
All the scripts listed in this topic are configured within the data source record. For more information, see [Configure data sources](https://servicenow-prod.fluidtopics.net/pIvHH_qzDp04r~p6WoXj6Q "Configure data sources to map UI elements to specific database fields using element identifiers, enabling the retrieval and display of data on input form screens. This mapping verifies that each UI element accurately reflects the corresponding data field within a record.").

## Default sample script {#data-source-script-examples__section_g31_xvm_p2c}

The following is the sample script provided within the Mobile App Builder. The script provides a template showing how to filter an existing table and to map specific fields to UI elements.

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

This sample script contains:

* The following parameters that define the data source:
  * <var class="keyword varname">valuesMapper</var>: This parameter is used to map the values from the data source to the UI elements.
  * <var class="keyword varname">Context</var>: This parameter specifies the context in which the data source is being used, such as an incident, change request, or any other table.
  {#data-source-script-examples__ul_mjx_cwm_p2c}
* The <var class="keyword varname">addRecordMapping</var> method is used to map the fields and consists of the following parameters:
  * Element identifier: The unique name you defined for the field you're mapping. In the example, this is `<short description>` and `<priority>`.
  * Glide record `<gr>`: This is used to reference any table within the instance, including custom tables.
  * Field name: This is the name of the field within the glide record. In the example, this is `<short description>` and `<priority>`.  
    Note:  
    A general guideline is to name the element identifier the same as the field name, to make the code easier to maintain and understand.
  {#data-source-script-examples__ul_lcm_3wm_p2c}
{#data-source-script-examples__ul_wpq_bwm_p2c}

## Script to map inputs configured in the input form {#data-source-script-examples__section_cny_nwm_p2c}

The following is an example script demonstrating how the <var class="keyword varname">ElementIdentifier</var> attribute of inputs configured in the Attributes \[sys_sg_input_attribute\] table is processed. The script contains examples of mapping an
input value to a column in the incident table of five inputs named <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>.

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

This code defines the function <var class="keyword varname">DataSource</var> that maps specific columns from the Incident \[incident\] table record to corresponding element identifiers. The following process occurs:

* Creates a <var class="keyword varname">GlideRecord</var> object for the incident \[incident\] table.
* Queries the table for a record with a specific <var class="keyword varname">sys_id</var> using a unique value from the <var class="keyword varname">context</var>.
* If a record is found, it maps the following columns to their correlated unique element identifier:
  * <var class="keyword varname">short_description</var> to <var class="keyword varname">input_1_short_description</var>
  * <var class="keyword varname">start_time</var> to <var class="keyword varname">input_2_start_time</var>
  * <var class="keyword varname">score</var> to <var class="keyword varname">input_3_score</var>
  * <var class="keyword varname">assigned_to</var> to <var class="keyword varname">input_4_assigned_to</var>
  * <var class="keyword varname">sys_id</var> to <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}

## Script to map descriptive elements associated with inputs or input sections in the input form {#data-source-script-examples__section_u2s_hxm_p2c}

The following is an example script demonstrating how to handle the <var class="keyword varname">ElementIdentifier</var> attribute of a descriptive element, configured in the descriptive element \[ sys_sg_descriptive_element\] table.

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

This code defines the function <var class="keyword varname">DataSource</var> that maps specific columns from the Incident \[incident\] table record to corresponding element identifiers. The following process occurs:

* Creates a <var class="keyword varname">GlideRecord</var> object for the incident \[incident\] table.
* Queries the table for a record with a specific <var class="keyword varname">sys_id</var> using a unique value from the <var class="keyword varname">context</var>.
* If a record is found, it maps the following columns to their correlated unique element identifier:
  * <var class="keyword varname">rich_text_1_col</var> (HTML type) to <var class="keyword varname">input_1_rich_text_descriptive_element_id </var>
  * <var class="keyword varname">plain_text_1_col </var>(String type) to <var class="keyword varname">input_1_text_descriptive_element_id</var>
  * <var class="keyword varname">image_1_col</var> (Image type) to <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}

## Script to map input actions associated with inputs in the input form {#data-source-script-examples__section_bjw_cym_p2c}

The following is an example script demonstrating how to handle the <var class="keyword varname">ElementIdentifier</var> attribute of input actions configured in the Input form action \[sys_sg_parameter_action\] table.

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

This code defines the function <var class="keyword varname">DataSource</var> that maps specific columns from an Incident \[incident\] table record to corresponding element identifiers. The following process occurs:

* Creates a GlideRecord object for the 'incident' table.
* Queries the table for a record with a specific <var class="keyword varname">sys_id</var> using a unique value from the <var class="keyword varname">context</var>.
* If a record is found, it maps the following columns to their correlated unique element identifier:
  * <var class="keyword varname">sys_id</var> to <var class="keyword varname">input_1_action_attachments</var> for handling attachment type input actions.
  * <var class="keyword varname">comment_by_agent </var>to <var class="keyword varname">input_1_action_comment </var>for handling comment type input actions.
  * <var class="keyword varname">sys_id</var> to <var class="keyword varname">input_1_navigation</var> for handling navigation type input actions with a record context.
  {#data-source-script-examples__ul_qvf_mzm_p2c}
{#data-source-script-examples__ul_dwj_kzm_p2c}

