Expression using FeatureSet to add contextual data from another layer in pop-up not returning results

360
9
Jump to solution
05-10-2021 12:20 PM
Labels (1)
FPGIS_FrancescaRohr
New Contributor II

Hello,

I am customizing the pop-up on my main layer (layer A) in a web map and want to include information from a separate layer (layer B). Both layers are point features. Layer A is tree points and Layer B is inspections on those trees, one inspection per tree. Not all trees have inspections. However, my expression is not returning the desired results.

Line 1 of my expression creates a unique id from two fields in layer A:

var treeuniqueid = Text($feature["Grant_ID"]+"_"+$feature["Tree_ID"])

Line 2 of my expression uses FeatureSetByName to access the attributes from layer B:

var inspection = FeatureSetByName($map,"UCF Tree Inspections - UCF Tree Inspections")

Line 3 adds in a filterStatement to match the records in layers A & B:

var filterStatement = "Tree_UniqueID = @treeuniqueid"

Lines 4&5 use Filter to only return the information for the selected tree point in the web map.

var inspected = Filter(inspection, filterStatement)
return inspected

In the expression window the results show that I am accessing layer B attributes:

FPGIS_FrancescaRohr_0-1620674078147.png

but I get this in the pop-up itself:

FPGIS_FrancescaRohr_1-1620674209549.png

Is using the created variable treeuniqueid to essentially 'join' the tables from the two layers an issue?

What else am I missing? Any and all help appreciated. Thank you, Francesca

 

 

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi @FPGIS_FrancescaRohr ,

Sorry for the delay, but I was stuck in some meetings. I just had a look at the data and I think I have the answer. As you can see it now returns the  number of inspections:

XanderBakker_0-1621019404268.png

There was just a tiny mistake in the expression. when you construct the SQL you use an underscore "_" when the data uses a hyphen "-". Also in my case the name of the layer was a bit different, but this could just be for me. 

View solution in original post

0 Kudos
9 Replies
XanderBakker
Esri Esteemed Contributor

Hi @FPGIS_FrancescaRohr ,

The problem, in this case, is that you are returning a featureset to the pop-up. That is something the pop-up can't visualize. It does show in the expression builder, but this does not mean that it will show in the pop-up. You will probably have to loop through the features in the featureset and construct the text that you want to return. 

Have a look at https://community.esri.com/t5/arcgis-online-documents/using-featuresetby-functions-in-arcade-to-dril... and the second code block where a list of maintenances of a hydrant is formatted and returned to the pop-up. 

0 Kudos
FPGIS_FrancescaRohr
New Contributor II

Hello @XanderBakker 

Thank you for the article link, it was very helpful. I simplified the expression from the article and customized it to work for my data:

var inspections = FeatureSetByName($map,"UCF Tree Inspections - UCF Tree Inspections")
var treeuniqueid = Text($feature["Grant_ID"]+"_"+$feature["Tree_ID"])
var sql = "Tree_UniqueID = @treeuniqueid"
Console(sql)
var inspection = Filter(inspections, sql)
var cnt = Count(inspection)
var history = ""
if (cnt > 0){
history = cnt + "inspection(s):"
}
else {
history = "No inspections"
}
return history

I changed var sql from:

var sql = "Tree_UniqueID = '" + treeuniqueid + "'" to:

var sql = "Tree_UniqueID = @treeuniqueid" because I wasn't getting any return in my pop-up. Now I get 'No inspections' even when an inspection has occurred. Obviously var sql line is incorrect. I followed the example given for attribute related data in https://www.esri.com/arcgis-blog/products/arcgis-online/data-management/pump-up-your-pop-ups-with-ar...

FPGIS_FrancescaRohr_0-1620922904299.png

I can't find any specific documentation on how to successfully create this variable. It's difficult to know the limits of Arcade - is there an issue with using a created variable as the 'field' on which to match (join) two data layers?  My hope is that I just haven't learned how to do it yet. 

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @FPGIS_FrancescaRohr ,

Quick question: does your data use a Relationshipclass? If so, you are probably better off using the "FeatureSetByRelationshipName" to get to the related records.

0 Kudos
FPGIS_FrancescaRohr
New Contributor II

Hi @XanderBakker 

No, the inspections are not a related table to the tree data. 

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @FPGIS_FrancescaRohr ,

Sorry for the delay, but I was in meetings all afternoon. I was looking at the expression and I can't see any problem with it. I assume as you do that it concerns the SQL. I think you are creating it correctly, but I can't validate without having access to the data. In case possible, can you share the data? You could create a group, share the data to that group and invite me using "xbakker.spx" to the group.

Some minor changes to your expression, but none that will solve the issue.

var inspections = FeatureSetByName($map, "UCF Tree Inspections - UCF Tree Inspections");
var treeuniqueid = $feature["Grant_ID"] + "_" + $feature["Tree_ID"];
var sql = "Tree_UniqueID = @treeuniqueid";
Console(sql);

var inspection = Filter(inspections, sql);
var cnt = Count(inspection);
var history = "";

if (cnt > 0) {
    history = "inspection(s): " + cnt;
} else {
    history = "No inspections";
}

return history;

 

0 Kudos
FPGIS_FrancescaRohr
New Contributor II

Hi @XanderBakker 

I have created an AGOL group - FROHR Private and invited you join. I have shared the UCF Tree Inspections layer and the CAL FIRE UCF Tree Data layer with this group. Both are views but should work for you. 

I made the small changes to the expression and, as you expected, continue to get a return of  'No inspections' for every tree point.

I appreciate your help on this. Francesca

XanderBakker
Esri Esteemed Contributor

Hi @FPGIS_FrancescaRohr ,

Sorry for the delay, but I was stuck in some meetings. I just had a look at the data and I think I have the answer. As you can see it now returns the  number of inspections:

XanderBakker_0-1621019404268.png

There was just a tiny mistake in the expression. when you construct the SQL you use an underscore "_" when the data uses a hyphen "-". Also in my case the name of the layer was a bit different, but this could just be for me. 

View solution in original post

0 Kudos
FPGIS_FrancescaRohr
New Contributor II

@XanderBakker  It's always something small! 😄 Nice job in spotting the teeny mistake which brought down the whole expression. And for pointing me in the right direction. Thank you very much! I can now use this as a base for adding additional, more complex, information from the contextual layer.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @FPGIS_FrancescaRohr ,

I'm glad it was fixed. If you need some more help further along the line, don't hesitate to tag me.

0 Kudos