Display parent fields in child record pop up

940
2
06-04-2021 03:51 PM
HayleighFisher
New Contributor III

Hi,

I have been trying to display a parent field in a child record pop-up and have not had any success, is this possible? I know it is possible to show child record info in the parent pop-up so I would assume the opposite is also possible. For my project I have site records which have an ID it has a 1:M relationship with it's child records, for example pipes and meters. The users are using field maps and want to be able to select the child record (such as a pipe) and to view the site record ID it is related to. Is it possible to add this information to the pop-up or as a label on the child feature?

 

Thank you,

Hayleigh 

0 Kudos
2 Replies
jcarlson
MVP Esteemed Contributor

You can certainly do this for the popup. However, you cannot do this for the label. The labeling profile in Arcade does not permit access outside of the individual feature being labelled.

In the popup, though, you can use any of the FeatureSetBy functions to get the parent layer. There is a function FeatureSetByRelationShipName, which is ideal for this. Rather than returning the entire layer as a FeatureSet, you instead get the subset of related records based on the input feature.

As you are going child -> parent in a 1:M relationship, you know you'll only have one record to deal with, so you can immediately call First on the returned FeatureSet to get the Feature itself.

Here's an expression written for the popup of an amenity inspection. Like your situation, it's a 1:M relationship between individual amenities and their periodic inspections. To grab, say, the name of the amenity and the preserve the amenity is located within, I use the following:

var id = $feature.guid

var rel_fs = FeatureSetByRelationshipName($feature,"ForestPreserveAmenities", ['name', 'forestpreserve'], false)

var parent = First(rel_fs)

return parent.name + ' in ' + parent.forestpreserve

 Which returns:

Parking in Blackberry Creek

If you've not used the FeatureSetByRelationshipName function before and are unsure of the 'relationship name' parameter, not to worry. In the expression builder built into the map viewer, you can find it in Globals -> Feature -> Related Records (at the bottom of the fields list) -> Relationship

jcarlson_0-1623033728852.pngjcarlson_1-1623033767410.png

Just click the blue link under the relationship to insert it into your expression.

If you just need a field or two, consider adding the fields and includeGeometry parameters to improve performance, though with a single record, it's likely to be a minimal difference.

- Josh Carlson
Kendall County GIS
HayleighFisher
New Contributor III

Hi Josh,

 

Thank you so much for the reply! This worked for me, however I did run into the issue where the Expression wouldn't save if there was data missing from the parent record. In order to bypass this I had to edit the web map json directly. 

Thanks again,

Hayleigh 

0 Kudos