Select to view content in your preferred language

attribute data to related record from parent feature using arcade

1269
8
09-30-2022 09:19 AM
Labels (3)
AdejumoBidemi
Occasional Contributor

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:

Spoiler

//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;
}

 

0 Kudos
8 Replies
JohannesLindner
MVP Frequent Contributor
  • You need to use a variable with the @ notation in the Filter() function. You already created that variable, but then you try to use $feature in the sql statement, which doesn't work.
  • You're trying to return from the wrong featuresets for p1 and p2.
  • It should be faster to do the loading, filtering and returning for each layer before going to the next layer. This way, you don't unneccessarily load data.
  • You don't need all those else's. If you return from a function, everything after that return statement isn't executed anymore.

 

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

 


Have a great day!
Johannes
0 Kudos
AdejumoBidemi
Occasional Contributor

Thanks so much Johannes. I tired the code and made the necessary adjustments as you suggest but I got the error below;

AdejumoBidemi_0-1664887871126.png

 

 

0 Kudos
JohannesLindner
MVP Frequent Contributor

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

 


Have a great day!
Johannes
0 Kudos
AdejumoBidemi
Occasional Contributor

No it generated same error

0 Kudos
JohannesLindner
MVP Frequent Contributor

That's it, I'm calling in backup! @jcarlson , any ideas?


Have a great day!
Johannes
jcarlson
MVP Esteemed Contributor

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?

- Josh Carlson
Kendall County GIS
0 Kudos
AdejumoBidemi
Occasional Contributor

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.

0 Kudos
AdejumoBidemi
Occasional Contributor

😀

0 Kudos