HOW TO

Show attachments from a related table/layer in the pop-ups in a web map

Last Published: March 10, 2022

Summary

Pop-ups in a map can be used to show information about features. Attribute data can be inserted into a pop-up, and attachments can be shown if the feature service is enabled to capture them. Attachment images can also be shown in the pop-up.

However, there  is currently no out-of-the-box functionality to show attachments from a related table/layer in the pop-ups on a web map in ArcGIS Online. 
There is an existing enhancement request to provide this functionality: 

  • ENH-000144845 : Allow the user the possibility to choose whether to display the attachments that are on a related table or the layer in ArcGIS Online Map Viewer or ArcGIS Operational Dashboard

Procedure

This article explains the workflow in Map Viewer, however, the same Arcade expression can be used in Classic Map Viewer too. 
  1. Click the layer on Layers list.
  2. On the Settings toolbar, click the Configure pop-ups icon to open pop-up configuration, as shown in the image below.
  3. Under Options, click Manage expressions.
  4. In the Pop-up Expressions dialog, click + Add expression.
adding an expression in the pop-up configuration dialog
  1. Add the following script and modify it to match your data as needed.
  2. Give the expression a name and click OK.
// first read out the ID of the selected feature (the primary key of the relationship in the parent layer, in this case "globalid")
var id = $feature.globalid;

// access the related table (in this example "relatedtable" is the name of the related table/layer on the map)
var tbl = FeatureSetByName($map, "relatedtable");

// create a sql expression to query related records based on the primary key and the foreign key for the relationship (in this case, "globalid" from the parent layer, and the "parnetglobalid" from the related layer/table)
var sql = "parentglobalid = '" + id + "'";

// filter the table using the sql expression
var related_data = Filter(tbl, sql);

// return an attribute value from the related record (objectid and id of the first attachment)
for (var row in related_data) {
    var reloid = row.objectid;}
    var AttachID = First(Attachments(row)).ID

// other url parameters (Part1 is the REST URL of the hosted feature layer
var Part1 = "https://services.arcgis.com/Wl7Y1m92PbjtJs5n/arcgis/rest/services/service_8d10508dd20f43e0a91faf21e4191f09/FeatureServer/1/"
var Part2 = "/attachments/"

//construct the attachment url
var url = Part1 + reloid + Part2 + AttachID

//return the url for the attachment 
return url
  1. Go back to the Pop-ups configuration panel and click + Add content.
  2. Click the curly braces { } next to the URL field.
  3. Select the expression added in step 5 above.
  4. Click Done.

Notice in the screenshot below that now an image is added to the media content in the map's pop-up.

sample web map with image added in a pop-up

Considerations/Limitations:
  • To show attachments from the related table/layer using this workflow, the feature service must be publicly accessible as it is not possible to generate a token with an Arcade expression to access a private layer. 
  • This Arcade expression returns the first attachment of the first related record so if a feature has more than one related record or has one related record with more than one attachment, only the first attachment of the first related record appears in the pop-up.

Article ID: 000027210

Software:
  • ArcGIS Online

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options