ARCED expression for PopUp

233
4
11-17-2021 06:26 AM
Labels (1)
HarishMuni
New Contributor
I want to configure a Popup in a webmap in AGOL
I have data fields that define purposes in a particular area.
for Example: Purpose A field - if the purpose exists the field value will be- Purpose A, and so on I want only the fields that have a value to appear in the popup Purpose A-Butterfly Garden
Purpose B-Null
Purpose C-Null
Purpose D-Dog Garden
Purpose E-Null
the Wonted end result -
Butterfly Garden, Dog Garden

and not
Butterfly Garden, , , Dog Garden,
I was thinking of writing an expression in ARCED that would create the list How do I write in ARCED an expression that asks first if there is a value in the field before it plants the value in the POPUP to avoid empty spaces

Thanks
Ori

 

0 Kudos
4 Replies
JasonGlidewell
New Contributor III

If I understand correctly, it sounds like an simple if/else will get it done for you.

Happy to help iif you need assitance setting up the argument.

if ( IsEmpty($feature["OCC_ELUM"] )) {
return "A"
}
else  {
return "B"
}

0 Kudos
JohannesLindner
MVP Regular Contributor

A simple if/else is not going to work here, because any number of purpose fields can have values. If you do a simple if/else chain like below, only the first purpose will be returned, completely ignoring possible other purposes.

// THIS IS WRONG, DON'T DO THIS
if(!IsEmpty($feature.PurposeA)) {
  // if PurposeA is filled ("Butterfly Garden" in the example), the expression will end here.
  // Other purpose fields (PurposeD - "Dog Garden") will be ignored!
  return $feature.PurposeA
}
if(!IsEmpty($feature.PurposeB)) {
  return $feature.PurposeB
}
if(!IsEmpty($feature.PurposeC)) {
  return $feature.PurposeC
}
if(!IsEmpty($feature.PurposeD)) {
  return $feature.PurposeD
}

Have a great day!
Johannes
0 Kudos
JasonGlidewell
New Contributor III

Maybe I am misunderstanding, but the way I've done this in the past is to use nested arguements in the if expression.

EX. if(IsEmpty($feature.Field_A)) && (IsEmpty($feature.Field_B)) == false){

return $feature.Field_B

0 Kudos
JohannesLindner
MVP Regular Contributor
// build an array of the purpose field values
var purposes = [
  $feature.PurposeA,
  $feature.PurposeB,
  $feature.PurposeC,
  $feature.PurposeD,
  $feature.PurposeE
]
// use that to build an array of non-empty purpose values
var non_empty_purposes = []                  // empty array
for(var p in purposes) {                     // loop through purposes
  if(!IsEmpty(purposes[p])) {                // if purpose is not empty (null or "")
    Push(non_empty_purposes, purposes[p])    // append to array
  }
}
// return the concatenated array as string
return Concatenate(non_empty_purposes, ", ")

Have a great day!
Johannes