Hi everyone,
I'm trying to use arcade to pull the address from 3 features. I want to pull the address into the related table iterating through the 3 features and pulling the first one found. The address will be pulled based on the global ID
Code:
//create featuresSets for each Layer in the service
var p1 = FeatureSetByName($map,"parcel (LogTest )")
var p2 = FeatureSetByName($map,"building (LogTest )")
var p3 = FeatureSetByName($map,"facilities (LogTest)")
//Filter your FeatureSets by Site ID
var GUID = $feature.GLOBALID
var p1_filter = Filter(p1, "GUID = @$feature.GLOBALID")
var p2_filter = Filter(p2, "GUID = @$feature.GLOBALID")
var p3_filter = Filter(p3, "GUID = @$feature.GLOBALID")
//Return the address of the parent feature
if(Count(p1_filter) > 0) {
return First(p2_filter).Address
}
else if(Count(p2_filter) > 0) {
return First(p3_filter).Address
}
else if(Count(p3_filter) > 0) {
return First(p3_filter).Address
}
else{
return null;
}
var GUID = $feature.GLOBALID
var p1 = FeatureSetByName($map,"parcel (LogTest )")
var p1_filter = Filter(p1, "GUID = @GUID")
if(Count(p1_filter) > 0) {
return First(p1_filter).Address
}
var p2 = FeatureSetByName($map,"building (LogTest )")
var p2_filter = Filter(p2, "GUID = @GUID")
if(Count(p2_filter) > 0) {
return First(p2_filter).Address
}
var p3 = FeatureSetByName($map,"facilities (LogTest)")
var p3_filter = Filter(p3, "GUID = @GUID")
if(Count(p3_filter) > 0) {
return First(p3_filter).Address
}
return null
Thanks so much Johannes. I tired the code and made the necessary adjustments as you suggest but I got the error below;
Huh... No idea.
Does it work if you take care of the formatting yourself?
var where = `GUID = '${$feature.GLOBALID}'`
var p1 = FeatureSetByName($map,"parcel (LogTest )")
var p1_filter = Filter(p1, where)
if(Count(p1_filter) > 0) {
return First(p1_filter).Address
}
var p2 = FeatureSetByName($map,"building (LogTest )")
var p2_filter = Filter(p2, where)
if(Count(p2_filter) > 0) {
return First(p2_filter).Address
}
var p3 = FeatureSetByName($map,"facilities (LogTest)")
var p3_filter = Filter(p3, where)
if(Count(p3_filter) > 0) {
return First(p3_filter).Address
}
return null
No it generated same error
That's it, I'm calling in backup! @jcarlson , any ideas?
It's been a while since I saw that error message, but I seem to recall it being something very trivial, and not what I expected...
I know this is in the "AGOL" space, but I just want to confirm: the expression is running in AGOL, correct? If it's Portal, though, what version are you on?
Also, are these layers really related, as in, they have a relationship class? If so, you could just use FeatureSetByRelationShipName, which pulls in related records, bypassing the need to apply a filter at all.
Also, GUID is a function in Arcade. Maybe try avoiding that term?
I've tried setting up a similar situation with test data (including characters like "(" in the layer name), and I can't get it to break the same way.
Any chance any of these layers are public so that we can test an expression against the real data?
Thanks so much @jcarlson and @JohannesLindner . I really appreciate. The error is from AGOL and they are related. I tried the FeatureSetByRelationShipName but still generated the same error.
No the data are not but I can request to make a part of it public.
😀