HOW TO

Use multiple Arcade IF statements in ArcGIS Online

Last Published: March 28, 2022

Summary

Custom expressions written in Arcade can be used to configure pop-ups in ArcGIS Online. These expressions can be used to generate new data with reference to a field with different values in a layer's existing fields. In some cases, multiple conditions must be set within a single logical operator, and therefore, the 'if...else if...else' logical operator can be utilized to specify the multiple conditions in the single code block.

This article provides the steps to reference values in a field and classify them using the 'if...else if...else' logical operator in ArcGIS Online Map Viewer. In this example, the value of the LEVEL_NO field is referenced to classify the marketing targets for each point symbol.

Procedure

  1. Open the map in Map Viewer. Click Layers on the Contents (dark) toolbar and select the <layer name> with the pop-up for editing.
The Map Viewer Contents (dark) toolbar with the Layers tab
  1. Click Configure pop-ups on the Settings (light) toolbar and click Manage expressions.
The Map Viewer Pop-ups pane used to navigate to the Map Viewer Pop-up expressions pane
  1. Click + Add expression to open the Arcade expression editor window.
The Map Viewer Pop-up expressions pane with the Add expression icon
  1. Specify the following Arcade expression in the Expression window. Modify accordingly to the desired field names and values with the else operator at the end of the expression. In the sample below, there are three conditions set using 'if' and 'else if', to return value1, value2, and value3, respectively, if the specified condition is fulfilled. To close the operator, the else operator is set to return values that do not fulfill any of the set conditions in the if...else if portion of the expression.
Note:
More conditions and return values can be set by adding more 'else if' operators.
if ( $feature["<field name>"] == <field1>) {
return "<value1>"
}
else if ( $feature["<field name>"] == <field2>) {
return "<value2>"
}
else if ( $feature["<field name>"] == <field3>) {
return "<value3>"
}

else {

return "<value4>"

}
  1. Rename the New expression and click OK.
Specifying the Arcade expression in the Map Viewer Expression window
  1. Click the Previous button above the newly created Arcade expression in the Pop-up expressions pane.
The Map Viewer Pop-up expressions pane with the newly added expression
  1. Click Fields list to expand the list of fields displayed in the pop-ups and click Select fields.
The Map Viewer Pop-up expressions pane displaying the location of the Fields list section
  1. Check the expression field and click Done.
The Map Viewer Select fields pane to select fields to be displayed in the pop-up

The image below shows the pop-up display without the Arcade expression.

An example of the Map Viewer pop-up without the Arcade expression

The image below shows the pop-up display with the Arcade expression.

An example of the Map Viewer pop-up with the Arcade expression enabled

Article ID:000027277

Software:
  • ArcGIS Online

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic