Multiple Literal Strings in Arcade

10-17-2022 11:07 AM
Occasional Contributor

I'm trying to create a calculated expression to populate a value in one of my fields. The expression gets the address of a feature that's within 100 feet of the feature the user is adding. If the expression doesn't get an address I want it to do the same process but with a different layer. I'm using literal strings in Arcade to populate the field. Can I not use multiple literal strings in the expression? Below is my Arcade expression.

if (IsEmpty(Geometry($feature))){
    return null

var case = FeatureSetByName($map,"Active Container Related SRs")

var bufferedLocation = Buffer($feature, 100, "feet")
var candidateParcels = Intersects(case, bufferedLocation)

var featuresWithDistances = []
for (var f in candidateParcels){
            "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
    var rcase = FeatureSetByName($map,"Active Recycling Container Related SRs")
    var rParcels = Intersects(rcase, bufferedLocation)
    var recycle = []
    for (var i in rParcels){
                "distance": Distance($feature, i, "feet"),
                "feature": i
    return `${recycle["feature"]["IncidentAddress"]}`

return `${closestFeatureWithDistance["feature"]["IncidentAddress"]}`


0 Kudos
1 Reply
Occasional Contributor III

It looks like the second "find the closest thing" loop is incomplete, you need to sort your list and return the first result like you did above.

0 Kudos