Pulling data from a related tables related table (Pop-up configuration)

1337
5
Jump to solution
02-03-2022 12:48 PM
cpenling
New Contributor III

I'm currently trying to create a pop-up which pulls data from related tables. 

I've been successful in puling data from the table immediately related to the feature layer. But there is a table related to that related table that I also want to pull data from. The feature layer is a polygon, the related table has species that occur within that polygon and the secondary related table is supplemental information about that species. 

Feature Layer <> Related Table <> Related Table

This is my current expression for my feature layer: 

var relatedrecords = FeatureSetByRelationshipName($feature,"Provincially_Tracked_Species_Detail");
var popupString = ""
for (var f in relatedrecords){
popupString += Text(f.Com_Name) + TextFormatting.NewLine +

"Scientific Name: " +
DefaultValue(f.Sci_Name, 'no data') + TextFormatting.NewLine +

"Taxon: " +
DefaultValue(f.Lower_Taxon, 'no data') + TextFormatting.NewLine +

"SARO Status: " +
DefaultValue(f.SARO_Status, 'no data') + TextFormatting.NewLine +
TextFormatting.NewLine
}
return popupString

 

These are my results: 

Pop-up Results.JPG

I have also made an expression for my first related table pulling data from the second related table but because it is an expression not a real field it won't let me use it like any of the other fields (as I did with other fields in the above example). 

Hopefully, this makes sense. If you have any suggestions on a solution, please let me know. 

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Pulling additional details would be just like your current expression, with the for loop being nested and repeated.

var relatedrecords = FeatureSetByRelationshipName($feature, "Provincially_Tracked_Species_Detail")

for (var f in relatedrecords){

    ... // your existing popup string stuff here

    var secondary_related = FeatureSetByRelationshipName(f, "whatever_the_other_relationship_name_is")

    for (var s in secondary_related){

        // Add more to your output string
        popupString += s.some_attribute
    }
}

 

Also, you may be interested to know that you can easily create a multiline string using a backtick string, and pipe in all the attributes at the same time.

These lines of code:

popupString += Text(f.Com_Name) + TextFormatting.NewLine +

"Scientific Name: " +
DefaultValue(f.Sci_Name, 'no data') + TextFormatting.NewLine +

"Taxon: " +
DefaultValue(f.Lower_Taxon, 'no data') + TextFormatting.NewLine +

"SARO Status: " +
DefaultValue(f.SARO_Status, 'no data') + TextFormatting.NewLine +
TextFormatting.NewLine

Are equivalent to these:

popupString += `${Text(f.Com_Name)}
Scientific Name: ${DefaultValue(f.Sci_Name, 'no data')}
Taxon: ${DefaultValue(f.Lower_Taxon, 'no data')}
SARO Status: ${DefaultValue(f.SARO_Status, 'no data')}

`

 

- Josh Carlson
Kendall County GIS

View solution in original post

5 Replies
jcarlson
MVP Esteemed Contributor

Pulling additional details would be just like your current expression, with the for loop being nested and repeated.

var relatedrecords = FeatureSetByRelationshipName($feature, "Provincially_Tracked_Species_Detail")

for (var f in relatedrecords){

    ... // your existing popup string stuff here

    var secondary_related = FeatureSetByRelationshipName(f, "whatever_the_other_relationship_name_is")

    for (var s in secondary_related){

        // Add more to your output string
        popupString += s.some_attribute
    }
}

 

Also, you may be interested to know that you can easily create a multiline string using a backtick string, and pipe in all the attributes at the same time.

These lines of code:

popupString += Text(f.Com_Name) + TextFormatting.NewLine +

"Scientific Name: " +
DefaultValue(f.Sci_Name, 'no data') + TextFormatting.NewLine +

"Taxon: " +
DefaultValue(f.Lower_Taxon, 'no data') + TextFormatting.NewLine +

"SARO Status: " +
DefaultValue(f.SARO_Status, 'no data') + TextFormatting.NewLine +
TextFormatting.NewLine

Are equivalent to these:

popupString += `${Text(f.Com_Name)}
Scientific Name: ${DefaultValue(f.Sci_Name, 'no data')}
Taxon: ${DefaultValue(f.Lower_Taxon, 'no data')}
SARO Status: ${DefaultValue(f.SARO_Status, 'no data')}

`

 

- Josh Carlson
Kendall County GIS
cpenling
New Contributor III

It worked! Thanks so much for your help and additionally your advice to simplify my code. Also, generally speaking thanks for your contribution and help on this forum. It's greatly appreciated!

cpenling
New Contributor III

For some reason the code works in the test but nothing shows in the pop-up. When I comment out the new section to that secondary related table, the information shows up fine. Do you know why this would be happening?

Expression with secondary related table sectionExpression with secondary related table sectionPop-up with secondary related table sectionPop-up with secondary related table sectionExpression without secondary related table sectionExpression without secondary related table sectionPop-up without secondary related table sectionPop-up without secondary related table section

0 Kudos
jcarlson
MVP Esteemed Contributor

Curious. I've seen this sort of thing happen before. I wonder if it has to do with a null value somewhere. Can you find out what UTM Zone the test is running against and check the popup of that feature?

Also, can you try to replace the "for (var s in secondary_related)" section with something else? Maybe just add Count(secondary_related) to the output string to make sure that it's finding something? Sometimes a for loop errors out when there's nothing in the featureset.

- Josh Carlson
Kendall County GIS
0 Kudos
cpenling
New Contributor III

Thanks again! It was due to my id field (Sci_Name) having null values. I had to keep those null values so I ended up putting in an if statement and that solved the problem. 

Pop-up Results 6.JPG

0 Kudos