HOW TO

Create a pop-up with field names and values from multiple fields sorted in descending order in ArcGIS Online and Portal for ArcGIS Map Viewer

Last Published: February 9, 2023

Summary

In ArcGIS Online and Portal for ArcGIS Map Viewer, pop-ups configured by Arcade expressions with multiple statements can be used to display and sort field names and values across multiple fields of a feature. This makes it easier to determine which product or issue has the highest or lowest incident within a polygon. This article provides an example and instructions using Arcade expressions to create a pop-up with field names and values from multiple fields sorted in descending order in Map Viewer.

The image below shows a Map Viewer pop-up with each field and records separated.

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 Comparator function returning IsEmpty() as the least value.
function Comp (a, b) {
  When(
    IsEmpty(a[1]), -1,
    IsEmpty(b[1]), 1,
    Iif(a[1]>b[1], 1, -1)
  );
};
  1. Define the variable for the array list. In this example, the arrays consist of the field names and the corresponding field value for each field.
var <variableName1> = [
  ["<fieldName1>", $feature.<fieldName1>],
  ["<fieldName2>", $feature.<fieldName2>],
  ["<fieldName3>", $feature.<fieldName3>],
  ["<fieldName4>", $feature.<fieldName4>],
  ["<fieldName5>", $feature.<fieldName5>],
  ["<fieldName6>", $feature.<fieldName6>],
  ["<fieldName7>", $feature.<fieldName7>],
  ["<fieldName8>", $feature.<fieldName8>],
  ["<fieldName9>", $feature.<fieldName9>],
];
  1. Specify the following statement to determine the sorting type. The code block below is an example of a descending sort. For an ascending sort, ignore the Reverse() function.
<variableName1> = Reverse(Sort(<variableName1>, Comp));
  1. Specify the following statement to return the sorted text values. In this example, additional text formatting were included in the code block. The end result has all brackets removed, and the commas changed to colon.
var <variableName2> = "";
for (var i in <variableName1>) {
  if (<variableName2> == "") {
    <variableName2> = Replace(Replace(Replace(<variableName1>[i], '["', ""), '",', ": "), ']', "");
  } else {
    <variableName2> += TextFormatting.NewLine + Replace(Replace(Replace(<variableName1>[i], '["', ""), '",', ": "), ']', "");
  }
}

return <variableName2>;

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

function Comp (a, b) {
  When(
    IsEmpty(a[1]), -1,
    IsEmpty(b[1]), 1,
    Iif(a[1]>b[1], 1, -1)
  );
};

var arr = [
  ["BREASTCANCER", $feature.BREASTCANCER],
  ["CARDIOVASCULAR", $feature.CARDIOVASCULAR],
  ["CERVICALCANCER", $feature.CERVICALCANCER],
  ["COLONCANCER", $feature.COLONCANCER],
  ["DIABETES", $feature.DIABETES],
  ["INFLUENZA", $feature.INFLUENZA],
  ["LUNGCANCER", $feature.LUNGCANCER],
  ["PROSTATECANCER", $feature.PROSTATECANCER],
  ["SKINCANCER", $feature.SKINCANCER],
];

arr = Reverse(Sort(arr, Comp));

var result = "";
for (var i in arr) {
  if (result == "") {
    result = Replace(Replace(Replace(arr[i], '["', ""), '",', ": "), ']', "");
  } else {
    result += TextFormatting.NewLine + Replace(Replace(Replace(arr[i], '["', ""), '",', ": "), ']', "");
  }
}

return result;
  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.
  3. Optionally, click and drag Reorder The Reorder icon next to the expression field to a new position under the Select fields section.

The image below shows the newly added Diseases-Sorted field with multiple field names and values sorted in a descending order in the pop-up after using the Arcade expression.

The pop-up displaying the newly added Diseases-Sorted field in Portal for ArcGIS Map Viewer

Article ID: 000029130

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