HOW TO

Display fields from a separate hosted table in pop-ups using Arcade in ArcGIS Online Map Viewer

Last Published: June 30, 2022

Summary

In ArcGIS Online, custom Arcade expressions can be used to configure the pop-ups in a web map. FeatureSet can be created from a feature layer in a portal item to display data from several layers and tables in the pop-ups. This article demonstrates the workflow to display fields from a separate hosted table in web map pop-ups using Arcade FeatureSet.

Note:
This workflow can be used for a hosted feature layer with a related table, or between a hosted feature layer and a seperate hosted table. Ensure the hosted feature layer and the hosted table contain an attribute field of the same name.

In this example, the groundwater levels data in a hosted table is accessed as a FeatureSet to be displayed as related information in the groundwater well stations pop-ups.

The image below is the hosted table of the groundwater levels data to be displayed as related information in the pop-up. Stations are listed once or multiple times in the table.

The attribute table of the Groundwater_Levels_Monthly_Mean hosted table.

The image below is the groundwater well station point feature pop-up containing only the information from the hosted feature layer.

The pop-up of a point feature representing a groundwater well station on a web map.

Procedure

  1. Navigate to the Expression box to add a custom Arcade expression.
    1. Open the map in ArcGIS Online Map Viewer.
    2. Click Layers on the Contents (dark) toolbar, and select the layer with the pop-up for editing.
    3. On the Settings (light) toolbar, click Pop-ups.
    4. In the Pop-ups pane, under Options, click Attribute expressions.
The Settings toolbar and the Pop-ups pane in Map Viewer.
  1. Click Add expression.
  1. Configure the Arcade expression in the Expression box.
    1. Access the hosted table as a FeatureSet in the hosted feature layer. Refer to ArcGIS Arcade: FeatureSetByPortalItem for more information on the parameters used in the function.
var portal = Portal("https://www.arcgis.com")
var RelatedTable = FeatureSetByPortalItem(portal,
    "<item ID>", <layer ID>, ['<field name>', '<field name>',
    '<field name>', '<field name>', '<date field name>'])
Note:
To identify the item ID and the layer ID of the hosted table, on the item details page, click View The View button. next to the URL section to open the hosted table in ArcGIS REST Services Directory. The item ID is listed in Service ItemId, and the layer ID is listed in the parenthesis next to the layer or table.
The ArcGIS REST Services Directory page of the hosted table.
  1. Declare and filter the related features in the hosted table and the hosted feature layer using a common attribute field.
var CommonAttr = $feature.<field name> 
var filterStatement = '<field name> = @CommonAttr' 

var relatedData = Filter(RelatedTable, filterStatement)
  1. Optionally, sort the related features using the OrderBy() function. The <date field name> must be a date field from the hosted table. In this example, ASC is used to sort the features in ascending order. To sort the features in descending order, replace ASC with DESC.
var relatedDataSorted = OrderBy(relatedData, '<date field name> ASC')
  1. Iterate through all the related features in the FeatureSet to build a pop-up string by looping. Refer to ArcGIS Arcade: For loops for more information. The DefaultValue() function is used to replace empty attributes with a default value or text. In this example, 'no data' and 'No measurements to show' are the default texts. Replace <field name> with the fields called in the RelatedTable variable in Step 2 (a).
var popupString = ''
for (var f in relatedDataSorted){
    
    popupString += Text(f.<date field name>, 'MMMM Y') + TextFormatting.NewLine +
    
        "<Text> " +
        DefaultValue(f.<field name>, 'no data') + TextFormatting.NewLine +
        
        "<Text> " +
        DefaultValue(f.<field name>, 'no data') + TextFormatting.NewLine +
        
        "<Text> " +
        DefaultValue(f.<field name>, 'no data') + TextFormatting.NewLine +
        TextFormatting.NewLine
}

DefaultValue(popupString, 'No measurements to show')

This is the full Arcade expression used in this example.

var portal = Portal("https://www.arcgis.com")
var RelatedTable = FeatureSetByPortalItem(portal,
    "426460a6ae7c43dcb", 0, ['STATION', 'MSMT_DATE',
    'RPE_WSE', 'GSE_WSE', 'WSE'])

var CommonAttr = $feature.STATION
var filterStatement = 'STATION = @CommonAttr'

var relatedData = Filter(RelatedTable, filterStatement)

var relatedDataSorted = OrderBy(relatedData, 'MSMT_DATE ASC')

var popupString = ''
for (var f in relatedDataSorted){
    
    popupString += Text(f.MSMT_DATE, 'MMMM Y') + TextFormatting.NewLine +
    
        "Depth to water surface (ft): " +
        DefaultValue(f.RPE_WSE, 'no data') + TextFormatting.NewLine +
        
        "Depth below ground surface (ft): " +
        DefaultValue(f.GSE_WSE, 'no data') + TextFormatting.NewLine +
        
        "Water Surface Elevation (ft): " +
        DefaultValue(f.WSE, 'no data') + TextFormatting.NewLine +
        TextFormatting.NewLine
}

DefaultValue(popupString, 'No measurements to show')
Note:
Use the Test button to check the custom script in a variable. The return command can be added at the end of the script to test the script.
The Expression box to be configured with custom Arcade expression.
  1. Rename the expression using the Edit button, and click Save to save the expression. In this example, the expression is renamed as 'Groundwater Levels expression'.
The Expression box and the custom Arcade expression.
  1. Add the custom expression to the pop-ups.
    1. In the Pop-ups pane, click Fields list.
    2. Click Select fields.
    3. Under Expressions, check the custom expression check box.
    4. Click Done.
The Select fields pane and the Expressions section.

The related data from the hosted table is displayed in the pop-up using the custom Arcade expression.

The pop-up of a point feature representing a ground water well station and the related data from the hosted table on a web map.

Article ID:000027928

Software:
  • ArcGIS Online

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic