Use hosted feature service repeat "related table" data for labels/popups.

1365
11
02-14-2021 11:43 PM
by Anonymous User
Not applicable

Data (environmental) is collected in S123 using "repeats" to identify samples (multiple) and their attributes. Data is held as an AGOL hosted feature service.

Aim: To display some attributes in the related table as a label (and/or popup) for the parent feature service, noting that the parent has the location data (dot on the map) and the related table has the desired attributes to display. The aim is to display this in Arcmap and/or ArcPro, noting that complex labels aren't supported in AGOL. 

So far, the furthest i've got is displaying related data in a popup in AGOL. The following Arcade code (which I modified from here) works in the AGOL environment (note: i'm no coding wiz! Just painfully and slowly modified existing code!)
_______________________________________________________
// Write a script to return a value to show in the pop-up.
// For example, get the average of 4 fields:
// Average($feature.SalesQ1, $feature.SalesQ2, $feature.SalesQ3, $feature.SalesQ4)
var related_table = FeatureSetById($datastore, "2");
var filter_query = "parentglobalid = '" + $feature["globalid"] + "'";
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) {

for (var relatead_data_row in related_data_filtered) {
output += "Sum of PFAS: " + relatead_data_row.Sum_PFAS + " (mg/kg)" + TextFormatting.NewLine
+ "PFOS: " + relatead_data_row.PFOS + " (mg/kg)" + TextFormatting.NewLine
+ "PFHxS: " + relatead_data_row.PFHxS + " (mg/kg)" + TextFormatting.NewLine
+ "PFOA: " + relatead_data_row.PFOA + " (mg/kg)" + TextFormatting.NewLine
+ "6:2 FTS: " + relatead_data_row.FTS_6_2 + " (mg/kg)";
}
} else {
output = "No Related Records...";
}

return output;

________________________

This gives me these nice popups as seen below: 

MichaelAshelford_0-1613373469544.png

Now, if I open this map in ArcPro, not only does the popup now not show anything, but if I copy this code to the label preferences in Arcade language I get the following error: 

MichaelAshelford_2-1613374654370.png

I assume this is something to do with it not referencing the location, but I really have no idea?

I've tried some other things too..following the ESRI article Label Related Table  and article showing this working on c-drive hosted data I gave this python code a crack replacing the source with the URL Source of the related table (prosperities in Arc Pro) but I get an error saying that it can't open the location, see code and error below: 
______________________

import arcpy
def FindLabel ([globalid], [Field_ID]):
key1 = [globalid] # Key field in feature class
key2 = "[parentglobalid]" # Key field in related table
L = [Field_ID] # Label field in feature class
L2 = "Sum_PFAS" # Label field in related table
myDataTable = r"https://services6.arcgis.com/m84fmcvTQusi2jIj/arcgis/rest/services/service_f1f4c7601263461a9615bd85e..."
cur = arcpy.da.SearchCursor(myDataTable, [key2, L2])
for row in cur:
if str(key1) == str(row[0]):
L = L + "\n" + str(row[1])
del cur
return L
______________________

MichaelAshelford_1-1613374504409.png

Basically, I'm all out of ideas! I wouldn't think something so simple, would be so difficult! Am I on the right track? Is there a simpler way of doing this? Thanks in advance!!!

0 Kudos
11 Replies
by Anonymous User
Not applicable

Hi @XanderBakker
Ah I see, no problem. 
Unfortunately this isn't just one map - it's multiple on every project. The intent is to improve efficiency, reduce manual transcription and use attributes from two single sources of truth for displaying data on a figure (so I don't want to be pasting the data in boxes etc.) 
If you (or anyone else who sees this) can think of any way that this is possible, that'd be awesome 🙂 

0 Kudos
DougBrowning
MVP Esteemed Contributor

I always use FeatureSetByName.  This all works in a popup but sounds like not a label.

if ($feature.EvalStatus == "Eval") {
var sql = "PlotKey = '" + $feature.PlotKey + "'";
var tbl = Filter(FeatureSetByName($map,"Species Richness"), sql);

var tblCnt = count(tbl)
if (tblCnt < 1) {
return "\n----No Species Richness form found!"
}
else if (tblCnt > 1) {
return "\n----More than 1 Species Richness form found!"
}
else {
return ''
}
}
else {
return ''
}

0 Kudos