Hi -
I am trying to customize some pop-ups to show basic information from related tables. My hosted feature layer is set up so that there is a point layer with a series of 1:M relationships to related tables. Relationships are all based on GlobalID/GUID. There is a public version of the hosted feature layer here.
I have two separate Arcade statements working properly, however it was not until I started configuring the pop-up that I realized these really should be combined into one expression so that the information returned in the pop-up makes sense.
I am unsure of how to combine these. I want to to return either of the statements below based on the "Purpose" from the Road Infrastructure point layer.
Return this expression if Pupose = Stream Crossing-B:
// Access 'Bridge Inspections' table as a FeatureSet
var portal = Portal("https://www.arcgis.com")
var bridges = FeatureSetByPortalItem(portal,
"ae306d66da414b7f83f1c7db4284a632", 2, ['Inspection_Date',
'Condition_Overall', 'Inspector_Initials'])
// Filter related features by using a common attribute
var GLOBALID = $feature.GlobalID
var filterStatement = 'Bridge_GlobalID = @GlobalID'
// Related features as a variable
var relatedData = Filter(bridges, filterStatement)
// Sort related features by newest to oldest
var relatedDataSorted = OrderBy(relatedData, 'Inspection_Date DESC')
// Build the pop-up string by iterating through all related features
var popupString1 = '';
if (Count(relatedDataSorted)>0) {
// Get the first feature in the sorted FeatureSet
var f = First(relatedDataSorted);
// Build the pop-up string
popupString1 = DefaultValue(f.Condition_Overall, 'No Condition Recorded') + " " + Text(f.Inspection_Date, 'MM/DD/YYYY') + " by " + DefaultValue(f.Inspector_Initials, 'No Inspector Recorded')
}
DefaultValue(popupString1, 'No bridge inspections on record')
Return this expression if Purpose = anything but Stream Crossing-B:
// Access 'Culvert Inspections' table as a FeatureSet
var portal = Portal("https://www.arcgis.com")
var culverts = FeatureSetByPortalItem(portal,
"ae306d66da414b7f83f1c7db4284a632", 1, ['Inspection_Date',
'Condition_Overall', 'Inspector_Initials'])
// Filter related features by using a common attribute
var GLOBALID = $feature.GlobalID
var filterStatement = 'Culvert_GlobalID = @GlobalID'
// Related features as a variable
var relatedData = Filter(culverts, filterStatement)
// Sort related features by newest to oldest
var relatedDataSorted = OrderBy(relatedData, 'Inspection_Date DESC')
// Build the pop-up string by iterating through all related features
var popupString1 = '';
if (Count(relatedDataSorted)>0) {
// Get the first feature in the sorted FeatureSet
var f = First(relatedDataSorted);
// Build the pop-up string
popupString1 = DefaultValue(f.Condition_Overall, 'No Condition Recorded') + " " + Text(f.Inspection_Date, 'MM/DD/YYYY') + " by " + DefaultValue(f.Inspector_Initials, 'No Inspector Recorded')
}
DefaultValue(popupString1, 'No culvert inspections on record')
This is what the pop-up looks like now with the two separate Arcade expressions - you can see how it doesn't make any sense. I'd like to only show the proper expression based on Purpose:

I know I cannot use Arcade to call another expression, and I am guessing that I need to use some sort of if statement to get this working, but I really do not even know where to start.
Any help would be very welcome!