How can I write code to make a field attribute from one service/feature to show up in a pop-up of another service/feature that is in the same map in ArcGIS online?
I am not a developer and have tried to follow some videos and tutorials, but all seems too advanced for me. No intersects/geometry involved, just using services/fields that have a relationship. This data is being collected in Survey123.
My scenario: I would like the field attribute "Day of Work" that is in Line Clearance Contractor-Daily Trimming Report to show up in the pop-up of the repeat location service.
I am creating a dashboard using this information and having it in one spot would be so very helpful.
Thanks, Elizabeth
It's a little hard to know without seeing the full schema of your layers. Are they truly related, and part of the same service, or do they simply share a field?
I've got a very similar solution in one of my webmaps I'd be happy to share with you, but it depends a lot on how the layers are set up.
The Not-Actually-Related Layer Solution
Given two layers, parcels and parcel sales, I can use the following Arcade expression on the parcels layer to bring in an attribute from the sales table.
// Assign feature id field to variable
var id = $feature.pin
// Get other layer
var otherLayer = FeatureSetByName($map,"Parcel_Sales")
// Filter other layer by matching id
var otherFeatures = Filter(otherLayer, 'property_key = @ID')
// Sort returned features
var sortedFeatures = OrderBy(otherFeatures, 'sale_date DESC')
// Grab the first feature in the FeatureSet
var f = First(sortedFeatures)
// Return sale amount of latest sale
return f.sale_amount
Here's how it looks in action:
Of course, there's no reason some of those functions couldn't be combined into one, but I kept them all separate for clarity.
Thanks Josh! I will give my best go at it and see if I can follow your example to get what I am striving towards!
Elizabeth