HOW TO

Split and rearrange text strings within a pop-up using Arcade expressions in ArcGIS Online and Portal for ArcGIS Map Viewer

Last Published: January 5, 2023

Summary

In ArcGIS Online and Portal for ArcGIS Map Viewer, Arcade expressions with multiple statements can be used to split and reposition text strings of a field within a pop-up. The repositioned text strings can be used for data management or search results optimization. This article provides an example and instructions using Arcade expressions to split and rearrange text strings within a pop-up for Map Viewer.

The image below shows a Map Viewer pop-up with the Forest_Name field and the text string records.

The pop-up of the layer in Portal for ArcGIS Map Viewer

Procedure

  1. Open the map in Map Viewer. Click Layers on the Contents (dark) toolbar, and select the layer with the pop-up for editing.
  2. On the Settings (light) toolbar, click Pop-ups > Options > Attribute expressions.
  3. Click + Add expression to open the Arcade expression editor window.
  4. In the editor window, specify a name for the new expression.
  5. In the Expression dialog box, insert the following Arcade expression.
    1. Define the variable with the function to split the text string and the blank space as a separator.
var <variableName1> = Split($feature.<featureName>, ' ')
  1. Define the variable with the function to count the number of splits for each record.
var <variableName2> = Count(<variableName1>)
  1. Specify the following statement to return a blank value when the field value is empty.
if (<variableName2> == 0) {
  return ''
}
  1. Specify the following statement to return the same text value when the field is a single word.
if (<variableName2> == 1) {
  return $feature.<featureName>
}
  1. Specify the following statement to rearrange the position of the second word to the first position when the field has two words.
if (<variableName2> == 2) {
  return <variableName1>[1] + ' ' + <variableName1>[0]
}
  1. Specify the following statement to rearrange the position of the first word to the third position when the field has three words.
if (<variableName2> == 3) {
  return <variableName1>[1] + ' ' + <variableName1>[2] + ' ' + <variableName1>[0]
}

The code block below is an example of the full working expression.

var arrName = Split($feature.Forest_Name, ' ')
var lenName = Count(arrName)
if (lenName == 0) {
  return ''
}
if (lenName == 1) {
  return $feature.Forest_Name
}
if (lenName == 2) {
  return arrName[1] + ' ' + arrName[0]
}
if (lenName == 3) {
  return arrName[1] + ' ' + arrName[2] + ' ' + arrName[0]
}
  1. Click Run to view a preview of the expression result. If the required result is achieved, click Done.
Specifying the Arcade expression in the Portal for ArcGIS Map Viewer editor window
  1. Click the Previous button above the Arcade expression in the Pop-up expressions pane.
The Portal for ArcGIS Map Viewer Pop-up expressions pane with the Previous icon above the newly created expression
  1. Click Fields list to expand the list of fields displayed in the pop-ups, and click Select fields.
  2. Check the expression field under the Expressions section, and click Done.

The image below shows the newly added Sorted Forest Names field with the rearranged values in the pop-up after using the Arcade expression.

The pop-up displaying the newly added Sorted Forest Names field in ArcGIS Online Map Viewer

Article ID: 000028916

Software:
  • ArcGIS Online
  • Portal for ArcGIS

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options