Select to view content in your preferred language

Using Arcade to Combine Fields if the field isn't empty

348
3
Jump to solution
08-14-2024 11:37 AM
Labels (1)
diamondu
Emerging Contributor

I'm currently using arcade in a popup to combine 4 fields into a single line in one field. This code below works but I'd like to make it better/cleaner, since it's possible that the "GPS" field is empty. I'm sure there is a way to write what is in the GPS field in parenthesis only if it has text in it, and not write anything if it is empty. I'm new to arcade and just struggling on how to write the logic for when and if statements. 

Currently if the GPS field doesn't have text in it the code writes:

SiteName (): Lat, Long

Trying to get to:

If GPS does have text in it: SiteName (GPS abbreviation): Lat, Long

If GPS does not have text in it: SiteName: Lat, Long

var oneline = $feature.Site + " (" + $feature.GPS + "): " + $feature.Latitude + ", " + $feature.Longitude 

return oneline

 

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

I left missed the closing parenthesis for the GPS text. Since I can't edit my post, it's updated here

IIf (IsEmpty($feature.GPS),
  `${$feature.Site}: ${$feature.Latitude}, ${$feature.Longitude}`,
  `${$feature.Site} (${$feature.GPS}): ${$feature.Latitude}, ${$feature.Longitude}`
)

 

View solution in original post

3 Replies
KenBuja
MVP Esteemed Contributor

You can do that this way. This uses an implicit return and template literals

IIf (IsEmpty($feature.GPS),
  `${$feature.Site}: ${$feature.Latitude}, ${$feature.Longitude}`,
  `${$feature.Site} (${$feature.GPS}: ${$feature.Latitude}, ${$feature.Longitude}`
)

 

KenBuja
MVP Esteemed Contributor

I left missed the closing parenthesis for the GPS text. Since I can't edit my post, it's updated here

IIf (IsEmpty($feature.GPS),
  `${$feature.Site}: ${$feature.Latitude}, ${$feature.Longitude}`,
  `${$feature.Site} (${$feature.GPS}): ${$feature.Latitude}, ${$feature.Longitude}`
)

 

diamondu
Emerging Contributor

Thank you so so much!!

0 Kudos