---
sourceDocument: Brazil ServiceNow AI Platform user interface
sourceDocumentLink: https://www.servicenow.com/docs/r/platform-user-interface

 Release :

    - brazil

ft:locale :

    - en-US

ft:publication_title :

    - Brazil ServiceNow AI Platform user interface

ft:clusterId :

    - platux

bundleId :

    - platux

workflow :

    - Platform


---

# Scripting for map pages

# Scripting for map pages {#ariaid-title1}

Release version: Brazil  
Updated September 10, 2026  
![](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 Scripting for map pages

The scripting capabilities on the Map Page form in ServiceNow allow customers to customize map characteristics such as marker appearance, displayed information, and behavior.
This enables visualization of records like incidents on maps with tailored icons, labels, and pop-up details, enhancing situational awareness and user interaction.
Show full answer Show less  

## Key Features

* **Map Item Attributes:** Attributes include `name`, `latitude`, `longitude`, `icon` URL, icon size (`iconwidth`, `iconheight`), linked record details (`tablename`, `sysid`), form view (`view`), custom HTML content (`html`), and optional marker labels with position offsets.
* **Adding Map Items:** Use the `map.addItem(glideRecord)` method, passing a valid GlideRecord to create map markers.
* **Smartphone Customization:** The `isMobile` variable allows conditional scripting to adapt icon sizes and behavior for smartphone users.
* **Basic and Advanced Scripting Examples:**
  * Display active, critical incidents with custom icons and sizes.
  * Adjust icon sizes dynamically based on the number of incidents per location.
  * Use the `html` attribute to create interactive pop-ups with links to incident lists.
  * Add marker labels that show dynamic data, such as incident counts, with customizable label positioning.

## Practical Application for ServiceNow Customers

By leveraging map page scripting, customers can visualize incident data geographically, making it easier to identify hotspots and respond effectively. Custom markers and labels improve map readability and user engagement, while smartphone-specific scripts ensure usability across devices. The ability to link map markers to detailed records or lists enhances navigation and operational efficiency.

## Next Steps

* Define map markers using GlideRecord queries relevant to your use case (e.g., incidents).
* Customize marker appearance and behavior using available attributes.
* Implement conditional scripting with `isMobile` for optimized mobile experiences.
* Use HTML pop-ups and marker labels to provide interactive and informative map interfaces.
* Explore related tasks such as setting up the Google Maps API and creating map page modules to integrate and extend map functionality.  
The Script field on the Map Page form allows the use of attributes or custom code to
define map characteristics, such as marker appearance, display information, and
more.

## Scripting map item attributes

The following attributes are available.  
Note:  
To create an item on the map, use the map.addItem(glideRecord) method. Pass a valid GlideRecord to addItem().
{#scripting-for-map-pages__table_a3s_kr5_cr__entry__2}

| Attribute | Description |
|-|-|
| name | Name used for identification. |
| latitude | If you define an address, latitude is not necessary. |
| longitude | If you define an address, longitude is not necessary. |
| icon | URL of the icon to display for the marker. If a custom icon is not specified, the default Google marker is used. |
| icon_width | Width of the icon. The default is 32. |
| icon_height | Height of the icon. The default is 32. |
| table_name | Table whose records display when the marker icon is clicked. Used with the sys_id attribute. |
| sys_id | Sys_id of the record that displays when the marker icon is clicked. Used with the table_name attribute. |
| view | View of the form displayed in the dialog box when the marker icon is clicked. |
| html | Arbitrary HTML code for the pop-up window. If used, this value overrides the dialog box. |
| marker_label | Optional marker icon label text. |
| label_offset_left | Optional attribute that is used with marker_label to define the horizontal position of the marker label. The default is 0. |
| label_offset_top | Optional attribute that is used with marker_label to define the vertical position of the marker label. The default is 0. |
[ ]

{#scripting-for-map-pages__table_a3s_kr5_cr}

## Scripting custom map page behavior for
smartphone {#scripting-for-map-pages__section_sx4_jtw_j1b}

If you plan to access the map page from a smartphone, you may want to set custom smartphone interface behavior using the isMobile variable. You can use the isMobile variable to set custom behavior for the smartphone view of the map. For example, you might set different values for the icon_width and icon_height attributes when isMobile is true.

## Basic map page script {#scripting-for-map-pages__section_q5n_ytw_j1b}

This script displays all active, critical incident locations.

    //setup new GlideRecord query on the incident table
    var now_GR = new GlideRecord("incident");
    //add condition for priority 1
    gr.addQuery('priority', '1');
    //add condition for active incidents
    gr.addActiveQuery();
    //execute the query
    gr.query();
     
    //loop through the list of incidents returned by the query
    while (gr.next()) {
     
     //create a new map item to display - linked to the current incident record
     var item = map.addItem(now_GR);
     //add the latitude value from the incident's location
     item.latitude = gr.location.latitude;
     //add the longitude value from the incident's location
     item.longitude = gr.location.longitude;
     //link to the icon image
     item.icon = "http://maps.google.com/mapfiles/kml/pal3/icon51.png";
     //set the icon size
     item.icon_width = "16";
     item.icon_height = "16";
    }

## isMobile map page script {#scripting-for-map-pages__section_ldd_v5w_j1b}

This script displays all active, critical incident locations with custom settings for smartphone users.

    //setup new GlideRecord query on the incident table
    var now_GR = new GlideRecord("incident");
    //add condition for priority 1
    gr.addQuery('priority', '1');
    //add condition for active incidents
    gr.addActiveQuery();
    //execute the query
    gr.query();
     
    //loop through the list of incidents returned by the query
    while (gr.next()) {
     
     //create a new map item to display - linked to the current incident record
     var item = map.addItem(now_GR);
     //add the latitude value from the incident's location
     item.latitude = gr.location.latitude;
     //add the longitude value from the incident's location
     item.longitude = gr.location.longitude;
     //link to the icon image
     item.icon = "http://maps.google.com/mapfiles/kml/pal3/icon51.png";
     
     //set the icon size (use smaller icons for smartphone users)
     if (isMobile) {
       item.icon_width = "12";
       item.icon_height = "12";
     }
     else { 
       item.icon_width = "16";
       item.icon_height = "16";
     }
    }

## Advanced map page script {#scripting-for-map-pages__section_blc_bvw_j1b}

This script displays the number of open incidents by location. It varies the size of the icon based on the number of open incidents for the location. Using the html parameter, it also displays the location name and number of incidents, as well as a link to the list of related incidents.

    //get the instances url so we can link back to it
    var uri = gs.getProperty("glide.servlet.uri");
    //create an aggregate query on the incident table
    var count = new GlideAggregate('incident');
    //set condition for active incidents
    count.addQuery('active', 'true');
    //set aggregate field to location to get count by location
    count.addAggregate('COUNT', 'location');
    //execute the query
    count.query();
     
    //loop through the results
    while (count.next()) {
     
     //get the current record's location
     var loc = count.location;
     //get the count of incidents for this location
     var locCount = count.getAggregate('COUNT', 'location');
     //only display location is there are active incidents
     if (locCount > 0) {
     //create new new map item for this location
     var item = map.addItem(count);
     //set lat/long from the location record
     item.latitude = loc.latitude;
     item.longitude = loc.longitude;
     //build the link to the list of incidents for the location
     var link = 'href=' + uri + 'incident_list.do?sysparm_query=active%3Dtrue^location%3D' + loc;
     //build the html value to be displayed when you click the map icon
     item.html='<a ' + link + '>' + loc.getDisplayValue() + ' (' + locCount + ')</a>';
     //link to the icon image
     item.icon = "http://maps.google.com/mapfiles/kml/pal3/icon51.png";
     //set the size of the icon based on the number of active incidents
     if (locCount < 5) {
     item.icon_width = "12";
     item.icon_height = "12";
     }
     else if (locCount < 15) {
     item.icon_width = "16";
     item.icon_height = "16";
     }
     else {
     item.icon_width = "32";
     item.icon_height = "32";
     }
     }
    }

## Map page marker label script {#scripting-for-map-pages__section_nyt_mvw_j1b}

Marker labels allow you to add dynamic text to markers. This example displays the active incident count at each location.

    //get the instances url so we can link back to it
    var uri = gs.getProperty("glide.servlet.uri");
    //create an aggregate query on the incident table
    var count = new GlideAggregate('incident');
    //set condition for active incidents
    count.addQuery('active', 'true');
    //set aggregate field to location to get count by location
    count.addAggregate('COUNT', 'location');
    //execute the query
    count.query();
     
    //loop through the results
    while (count.next()) {
     
     //get the current record's location
     var loc = count.location;
     //get the count of incidents for this location
     var locCount = count.getAggregate('COUNT', 'location');
     //only display location is there are active incidents
     if (locCount > 0) {
     //create new new map item for this location
     var item = map.addItem(count);
     //set lat/long from the location record
     item.latitude = loc.latitude;
     item.longitude = loc.longitude; 
     
     //create a marker label with the count
     item.marker_label = locCount;
     //define label offset for proper position
     item.label_offset_left = -4;
     item.label_offset_top = -20;
     
     //option to define table and record for label hyperlink
     //setting table and sys_id will override the use of html parameter
     //item.table = 'cmn_location';
     //item.sys_id = loc;
     
     //build the link to the list of incidents for the location
     var link = 'href=' + uri + 'incident_list.do?sysparm_query=active%3Dtrue^location%3D' + loc;
     //build the html value to be displayed when you click the map icon
     item.html='<a ' + link + '>' + loc.getDisplayValue() + ' (' + locCount + ')</a>';
     
     //link to the icon image
     item.icon = "images/red_marker.png";
     //set the size of the icon based on the number of active incidents
     item.icon_width = 24;
     item.icon_height = 24;
     
     }
    }

**Related tasks**   

* [Set up Google Maps API](https://www.servicenow.com/docs/YEBEXUhadLhl63_QvFRlpA "You enable the geolocation feature using the appropriate entries from a Google Maps API for Business license, or a Google Maps JavaScript API Key.")
* [Create a map page](https://www.servicenow.com/docs/BOGFzdNpverSN_GueJFLeA "Your ServiceNow instance provides several default map pages. You can also create custom map pages with the script examples described in this page.")
* [Create a map page module](https://www.servicenow.com/docs/5WOW13hnrRhqVldGLYUOwA "You can create a new application module for desktop or smartphone users to display a Google map page.")
* [Create an advanced Map Page](https://www.servicenow.com/docs/yHj9XhIh8TppF88UeiCCAA "Use advanced configuration to set up Map Pages without scripting.")
* [Set map application scope](https://www.servicenow.com/docs/eJebDY8D96SPzDXYZMccdg "Enable map application scope to specify which application can modify your Map Page configuration.")
* [Create a smartphone map page module](https://www.servicenow.com/docs/5VEuf4eaP33OoR0~pHTX~A "You can create a custom smartphone module that links directly to a map page.")

