Select to view content in your preferred language

Arcade Expression Error

464
4
12-11-2024 09:21 AM
Labels (3)
PaulMAlexander
Emerging Contributor

Afternoon everyone. I have created an attribute rule that when i update a field in one polygon, it updates the same field in an intersecting polygon. When I check the expression to validate it, it says it is valid. When I run it, I recieve and error message stating,  " The index passed was not within the valid range." Any ideas on why this may occur?

0 Kudos
4 Replies
CodyPatterson
MVP Regular Contributor

Hey @PaulMAlexander 

Any chance you could post a screenshot of the rule an error?

Cody

0 Kudos
jcarlson
MVP Esteemed Contributor

Pro validates your expression based on a subset of records, so it may not know about potential values elsewhere in your data. Or for a spatial operation, it sees that the expression is valid, but once it tries to perform the steps you wrote, it hits an error.

For intersections, that usually means you've got a feature that does not intersect with anything from your other layer. If you don't have it already, throw in a quick check to make sure that the intersection has features in it.

// your other code here
// let's call the intersection "xs"

var xs = Intersects($feature, someOtherLayer)

// add a check, if there are > 0 features, do what you need
if( Count(xs) > 0 ){
  return First(someOtherLayer)['someAttribute']
} else {
  return 'No Intersecting Feature Found'
}
- Josh Carlson
Kendall County GIS
MikeMillerGIS
Esri Frequent Contributor

Just a comment on Josh's code.  Calling Count and then First results in an extra query.  For optimal performance, just call First and check if the result is valid.

 


var xs = Intersects($feature, someOtherLayer)
var intersected_feature = First(someOtherLayer)
if (IsEmpty(intersected_feature)){
  return 'No Intersecting Feature Found'
}
return intersected_feature['other_attribute']
jcarlson
MVP Esteemed Contributor

Thanks!

- Josh Carlson
Kendall County GIS
0 Kudos