Select to view content in your preferred language

Pull in Most Recent Date Inspected from one Layer into another in Pop-Up Using Arcade

397
2
08-10-2023 06:56 AM
Labels (2)
MelanieBass
New Contributor III

I am working on configuring the pop-ups on our hydrant layer to automatically pull in the most recent date inspected from a different layer: Hydrant Inspection layer. I want it to pull the most recent date if there is more than one date inspected for a given hydrant, which in many cases there are. I have been wracking my brain on an arcade statement but nothing I get works. I am not sure if I need to do an Intersects function with hydrant or OrderBy or First. I am lost.  I would even love to have it pull in as an attribute rule inside of ArcGIS pro for the layer but for now I will settle on getting an arcade for the pop-up. If anyone has any suggestions, they would be much appreciated. 

2 Replies
JohannesLindner
MVP Frequent Contributor
var all_inspections = FeaturesetByName($map, "Inspections")

var hydrant_id = $feature.HydrantID
var hydrant_inspections = Filter(all_inspections, "HydrantID = @hydrant_id")

var sorted_inspections = OrderBy(hydrant_inspections, "InspectionDate DESC")

var latest_inspection = First(sorted_inspections)
if(latest_inspection == null) { return "No inspection found" }

return latest_inspection.InspectionDate

Have a great day!
Johannes
0 Kudos
MelanieBass
New Contributor III
var all_inspections = FeaturesetByName($map, "Hydrant Inspections")

var hydrant_id = $feature.HydrantID
var hydrant_inspections = Filter(all_inspections, "HydrantID = @hydrant_id")

var sorted_inspections = OrderBy(hydrant_inspections, "DateInspected DESC")

var latest_inspection = First(sorted_inspections)
if(latest_inspection == 'December 29, 1899') { return "No inspection found" }

return latest_inspection.DateInspected
 
this is what I put in and I am getting the invalid parameter error. Is the "DateInspected DESC" supposed to be a field? The field for Date Inspected is DateInspected. Any other suggestions? Thank you for your help! I appreciate it. @JohannesLindner 
0 Kudos