Arcade Expression to Show Related Data in AGOL and FieldMaps Popup from Survey123 Entry

350
3
03-07-2023 08:01 AM
Labels (1)
JanicePulver
New Contributor II

I am trying to show in AGOL, a Dashboard, and FieldMaps pop ups the last inspection date for an outfall inspection. My crew enters in the data in a Survey123 survey from a hyperlink in FieldMaps. The data from the survey is also input into a related table.  I was trying to follow along with this blog post https://community.esri.com/t5/arcgis-online-blog/show-related-data-or-tables-in-pop-ups-with-arcade/...

but I'm not able to figure out the "//Filter related features by using a common attribute section". I think it has to do with my GUID field relating back to the GlobalID in the parent layer. Might also be that most of the data doesn't have a related entry to it. Below is the expression I have so far:

// Access 'Groundwater Levels Monthly Mean' table as a FeatureSet
var waterLevels = FeatureSetByPortalItem(Portal('https://www.arcgis.com'),
"4b21a92f2b38444793cf1ae1192476e4", 3, ['NodeNumber', 'MajorMinor',
'DateCurrent'])

// Filter related features by using a common attribute
var globalid = $feature.globalid
var filterStatement = 'parentglobalid = @globalid'

// Related features as a variable
var relatedData = Filter(waterLevels, filterStatement)

// Sort related features by oldest to newest
var relatedDataSorted = OrderBy(relatedData, 'DateCurrent DESC')

// Build the pop-up string by iterating through all related features
var popupString = ''
for (var f in relatedDataSorted){

popupString +=

"Outfall ID: " +
DefaultValue(f.NodeNumber, 'no data') + TextFormatting.NewLine +

"Last Formal Outfall Inspection: " +
DefaultValue(f.DateCurrent, 'no data') + TextFormatting.NewLine +

"Outfall Type: " +
DefaultValue(f.MajorMinor, 'no data') + TextFormatting.NewLine +
TextFormatting.NewLine
}

DefaultValue(popupString, 'No formal inspection data to show')

 

I was going section by section with the expression, so this does work and returns values in the field 

// Acess 'Groundwater Levels Monthly Mean' table as a FeatureSet
var waterLevels = FeatureSetByPortalItem(Portal('https://www.arcgis.com'),
"4b21a92f2b38444793cf1ae1192476e4", 3, ['DateCurrent'])

return waterLevels

It is when I try the next section where I run into issues. 

Parent layer "Outfalls", showing the GlobalID for NodeNumber WOC_24OF0_00.

JanicePulver_2-1678204493516.png

Child layer, "DryWeatherScreening" showing the GUID field for WOC_24OF0_00, same as the parent layer's GlobalID.

JanicePulver_3-1678204577685.png

I have seen some issues of this expression not showing up in Field Maps, but I am ok with that for now. 

Thanks!

Janice

 

 

 

0 Kudos
3 Replies
JohannesLindner
MVP Frequent Contributor

To post code:

JohannesLindner_0-1677736512957.png

JohannesLindner_1-1677736529803.png

 

You didn't adapt the filter query to your data. This should work:

// Filter related features by using a common attribute
var globalid = $feature.globalid
var filterStatement = 'GUID = @globalid'  // GUID instead of parentglobalid

Have a great day!
Johannes
0 Kudos
JanicePulver
New Contributor II

Sorry I didn't know how to add code like that!

I tried this below (excluding the pop-up section for now), and it doesn't pull any values. 

// Access 'Groundwater Levels Monthly Mean' table as a FeatureSet
var waterLevels = FeatureSetByPortalItem(Portal('https://www.arcgis.com'),
"4b21a92f2b38444793cf1ae1192476e4", 3, ['NodeNumber', 'MajorMinor',
'DateCurrent'])

// Filter related features by using a common attribute
var GlobalID = $feature.GlobalID
var filterStatement = 'GUID = @GlobalID'

// Related features as a variable
var relatedData = Filter(waterLevels, filterStatement)

// Sort related features by oldest to newest
var relatedDataSorted = OrderBy(relatedData, 'DateCurrent DESC')

return relatedDataSorted

JanicePulver_0-1678214132787.png

 

0 Kudos
NorthSouthGIS
Occasional Contributor II

It is returning the related data but as a featureset, you need to parse it out. See solution here: https://community.esri.com/t5/arcgis-online-questions/display-related-records-in-a-popup-in-a-nice-t...

0 Kudos