HOW TO
This article shows how to use Arcade to display data from another table containing a common field in a layer's pop-up window, in ArcGIS Pro and in ArcGIS Online or ArcGIS Enterprise. This can be a related table for example, but not necessarily.
var related_table = FeatureSetByName($datastore, "table"); var filter_query = "field_table= '" + $feature["field_class"] + "'"; var related_data_filtered = Filter(related_table, filter_query); var related_data_filtered_count = Count(related_data_filtered); var output = ""; if (related_data_filtered_count > 0) { output = "Total of " + related_data_filtered_count + " records : "; for (var related_data_row in related_data_filtered) { output += '<br>' + related_data_row.field1_table+ " - " + related_data_row.field2_table; } } else { output = "No Related Records..."; } return { type : 'text', text : output }
Note: By adding + related_data_row.fieldX_table +', ' to line 10, you can add the number of fields you want from the second table.
An example pop-up is shown in the following image:
Publish the expression after configuring it in ArcGIS Pro as described above, or click Add content in the pop-up window and click Arcade.
var related_table = FeatureSetByName($datastore, "table"); var filter_query = "field_table= '" + $feature["field_class"] + "'"; var related_data_filtered = Filter(related_table, filter_query); var related_data_filtered_count = Count(related_data_filtered); var output = ""; if (related_data_filtered_count > 0) { output = "Total of " + related_data_filtered_count + " records : " + TextFormatting.NewLine; for (var related_data_row in related_data_filtered) { output += related_data_row.field1_table+ " - " + related_data_row.field2_table +', ' + TextFormatting.NewLine; } } else { output = "No Related Records..."; } return output
Note: The output is slightly different from the previous code in that text is returned rather than a JSON block, and it uses the TextFormatting.NewLine line break, which does not work on ArcGIS Pro 3.X before version 3.3 (BUG-000162232), as the <br> code doesn't work in Map Viewer Classic.
Since we do not really use the relationship class, but rather link layers via common field values, we can link another table to this related table.
For example, it is possible to display the departments that make up a region, then the communes for each of these departments:
//First related table var related_table = FeatureSetByName($datastore, "departments"); //Second related table var related_related_table = FeatureSetByName($datastore, "communes"); //Filter query on the first related table with the feature class field var filter_query = "region_name= '" + $feature["name"] + "'"; //Filtered data from the first related table var related_data_filtered = Filter(related_table, filter_query); //Count of the filtered data from the first table var related_data_filtered_count = Count(related_data_filtered); //Output initialization var output = ""; //Check if data filtered exist from the first related table if (related_data_filtered_count > 0) { //Write in the output the number of data filtered output = "Total of " + related_data_filtered_count + " records : " + "<br>"; //Browse the rows of the first table for (var related_data_row in related_data_filtered) { //Write in the output the data from the selected fields from the first table output += related_data_row.department_number+ " - " + related_data_row.department_name +', ' + '<br>'; //Filter query on the second related table with the field from the first related table var related_filter_query = "dept_name= '" + related_data_row.department_name + "'"; //Filtered data from the second related table var related_related_data_filtered = Filter(related_related_table, related_filter_query); //Count of the filtered data from the second table var related_related_data_filtered_count = Count(related_related_data_filtered); //Check if data filtered exist from the second related table if (related_related_data_filtered_count > 0) { //Browse the rows of the second table for (var related_related_data_row in related_related_data_filtered) { //Write in the output the data from the selected fields from the second table output += " " + related_related_data_row.commune_name+', ' + '<br>'; } }else{ //If no row selected in second table, write nothing output += ""; } } } else { //If no row selected in first table, write that there is no data output = "No Related Records..."; } return { type : 'text', text : output }
An example result in ArcGIS Pro is shown in the next image:
Article ID: 000035545
Get help from ArcGIS experts
Download the Esri Support App