I'm trying to use a calculated expression to auto populate several fields in a layer that I'm collecting. I have 3 expressions that are doing basically the same thing, but only 2 of the 3 expressions work. I get an error that says Failed to Calculate and because of this error I can't submit the collected point. Below is the Arcade expression that I'm using. The 3 calculated expressions are using this same code, but pulling data from different layers from the map.
if (IsEmpty(Geometry($feature))){
return null
}
var parcels = FeatureSetByName($map,"Parcels")
var bufferedLocation = Buffer($feature, 100, "feet")
var candidateParcels = Intersects(parcels, bufferedLocation)
var featuresWithDistances = []
for (var f in candidateParcels){
Push(featuresWithDistances,
{
"distance": Distance($feature, f, "feet"),
"feature": f
}
)
}
function sortByDistance(a,b){
return a["distance"] - b["distance"]
}
var sorted = Sort(featuresWithDistances, sortByDistance)
var closestFeatureWithDistance = First(sorted)
if (IsEmpty(closestFeatureWithDistance)){
return null
}
return `${closestFeatureWithDistance["feature"]["ADDRESS"]}`