Select to view content in your preferred language

How to add multiple If/else statements in arcade?

1361
1
10-10-2019 06:09 AM
BlakeLiss
New Contributor

Hello All,

I am trying to write a script with multiple If/else statements because I am needing to calculate a field with multiple fields, but some of these fields have null values. The script I have is:

$feature.AddressNumber + $feature.AddNum_Suf + " " + $feature.StreetNamePreDirectional + " " + $feature.StreetNamePreType + " " + $feature.StreetName + " " + $feature.StreetNamePostType + "," + " " + $feature.PostalCommunityName + " " + $feature.PostalCode

if (IsEmpty($feature.AddressNumber)){
return ""
} else {
return $feature.AddressNumber
}
if (IsEmpty($feature.AddNum_Suf)){
return ""
} else {
return $feature.AddNum_Suf
}
if (IsEmpty($feature.StreetNamePreDirectional)){
return ""
} else {
return $feature.StreetNamePreDirectional
}
if (IsEmpty($feature.StreetNamePreType)){
return ""
} else {
return $feature.StreetNamePreType
}
if (IsEmpty($feature.StreetName)){
return ""
} else {
return $feature.StreetName
}
if (IsEmpty($feature.StreetNamePostType)){
return ""
} else {
return $feature.StreetNamePostType
}

The problem I am having is that the script is only returning the "$feature.AddressNumber". I am very novice with scripts but am stuck with what to do on this one. Any help is appreciated.

0 Kudos
1 Reply
XanderBakker
Esri Esteemed Contributor

Hi Blake Liss ,

I assume you want to construct an address line from multiple fields. When the code hits a line with "return" it will stop there. You will have to use variables to store the corrected field data and concatenate those at the end of the expression.

So you will have to do something like this for each field:

var AddressNumber = "";
if (!IsEmpty($feature.AddressNumber)) {
    AddressNumber = $feature.AddressNumber;
}

and at the end concatenate the variable AddressNumber with the other variable and return that result.

0 Kudos