Select to view content in your preferred language

Help with arcade expression

1337
3
Jump to solution
08-30-2022 07:22 AM
Robswann
Occasional Contributor

I am trying to pull from a feature set the location by filtering it by the relationship ID. I have similar formulas that work fine, but for some reason I am having trouble with this one. I have the following, could someone please help? The below rule is working, but pulling the first row from attribute table. Thanks

 

var Land = FeatureSetByName($datastore, "Land", [ "Location","Name","County","School_District","ID"]);

VAR LOCATION = FILTER(LAND,"ID=$feature.ID")

FOR(VAR I IN LAND)
RETURN I.LOCATION

 

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Alum

You're telling your DBMS to use the literal SQL query "ID = $feature.ID". This isn't a valid where clause and so it fails.

What you want to do is store the $feature.ID in a variable and use the @ notation of Filter() to take care of the type formatting for you.

Also, you aren't looping over the filtered feature set, but over the whole table...

var Land = FeatureSetByName($datastore, "Land", [ "Location", "Name", "County", "School_District", "ID"]);

var id = $feature.ID
var related = Filter(Land,"ID=@id")
var location = First(related)

if(location == null) {
    // no related features found -> return a default value
    return null
}
// else return the related feature's ID
return location.ID

 


Have a great day!
Johannes

View solution in original post

3 Replies
JillianStanford
Frequent Contributor

Hi,

Do you mean to loop through the original dataset or the filtered dataset? Also, I'm not sure if the curly braces are required in Arcade.

https://developers.arcgis.com/arcade/guide/logic/#for-loops

Does the following work?

var Land = FeatureSetByName($datastore, "Land", [ "Location","Name","County","School_District","ID"]);

VAR LOCATION = FILTER(LAND,"ID=$feature.ID")

FOR(VAR I IN LOCATION ) {
     RETURN I.LOCATION

}

0 Kudos
JohannesLindner
MVP Alum

You're telling your DBMS to use the literal SQL query "ID = $feature.ID". This isn't a valid where clause and so it fails.

What you want to do is store the $feature.ID in a variable and use the @ notation of Filter() to take care of the type formatting for you.

Also, you aren't looping over the filtered feature set, but over the whole table...

var Land = FeatureSetByName($datastore, "Land", [ "Location", "Name", "County", "School_District", "ID"]);

var id = $feature.ID
var related = Filter(Land,"ID=@id")
var location = First(related)

if(location == null) {
    // no related features found -> return a default value
    return null
}
// else return the related feature's ID
return location.ID

 


Have a great day!
Johannes
Robswann
Occasional Contributor

Very Helpful. Thank so much!

0 Kudos