HOW TO

Identify a range of missing numbers in a field using Arcade in Portal for ArcGIS and ArcGIS Online Map Viewer

Last Published: June 6, 2024

Summary

In Portal for ArcGIS and ArcGIS Online Map Viewer, automatically identifying missing numbers in a range can streamline the process of error detection and correction. This can be particularly important in large datasets where manual checking would be impractical.

This article describes the workflow to identify a range of missing numbers in a field for pop-ups using Arcade in Portal for ArcGIS and ArcGIS Online Map Viewer. In this example, some numbers are missing from the range of numbers (1 to 20) listed in the TestNumber field, as shown in the image below.

The attribute table in ArcGIS Online   

Procedure

  1. In Portal for ArcGIS or ArcGIS Online Map Viewer, open the web map containing the number dataset.
  2. On the Contents (dark) toolbar, click Layers to open the Layers pane and select the layer with the pop-up intended to be configured.
  3. On the Settings (light) toolbar, click Pop-ups.
  4. In the Pop-ups pane, click Attribute expressions under Options.
  5. In the Attribute expressions pane, click + Add expression.
  6. In the editor window, create a name for the Arcade expression and specify the Arcade expression.
    1. Create an array representing the range of the desired numbers. In this example, the range is set from 1 to 20.
var range = [];
for (var i = 1; i <= 20; i++) {
    Push(range, i);
}
  1. Collect all values from the selected layer's features. Replace '<layerName>' and '<fieldName>' with the layer and field names respectively.
var features = FeaturesetByName($map, "<layerName>", ["<fieldName>"]);
  1. Initialize an array to store the numbers.
var testNumbers = [];
  1. Iterate through the features and collect the numbers.
for (var f in features) {
    if (!IsEmpty(f.TestNumber)) {
        Push(testNumbers, Number(f.TestNumber));
    }
}
  1. Check if the array of the numbers is empty.
if (Count(testNumbers) == 0) {
    return "No test numbers available.";
}
  1. Sort the array of the numbers.
testNumbers = Sort(testNumbers);
  1. Initialize an empty array to store the missing numbers.
var missingNumbers = [];
  1. Loop through the specified range and add the missing numbers to the 'missingNumbers' array.
for (var i in range) {
    if (IndexOf(testNumbers, range[i]) == -1) {
        Push(missingNumbers, range[i]);
    }
}
  1. Convert the 'missingNumbers' array to a string.
var missingNumbersString = Concatenate(missingNumbers, ", ");
  1. Return the missing numbers or a message if no numbers are missing.
if (Count(missingNumbers) == 0) {
    return "No missing test numbers within the range 1 to 20.";
} else {
    return "Missing test numbers within the range 1 to 20: " + missingNumbersString;
}

The code below shows the example of the full working script.

var range = [];
for (var i = 1; i <= 20; i++) {
    Push(range, i);
}

var features = FeaturesetByName($map, "Pointsss", ["TestNumber"]);

var testNumbers = [];

for (var f in features) {
    if (!IsEmpty(f.TestNumber)) {
        Push(testNumbers, Number(f.TestNumber));
    }
}

if (Count(testNumbers) == 0) {
    return "No test numbers available.";
}

testNumbers = Sort(testNumbers);

var missingNumbers = [];

for (var i in range) {
    if (IndexOf(testNumbers, range[i]) == -1) {
        Push(missingNumbers, range[i]);
    }
}

var missingNumbersString = Concatenate(missingNumbers, ", ");

if (Count(missingNumbers) == 0) {
    return "No missing test numbers within the range 1 to 20.";
} else {
    return "Missing test numbers within the range 1 to 20: " + missingNumbersString;
}
  1. Click Done.
  1. In the Attribute expressions pane, click the Previous The Previous button button above the newly created Arcade expression.
  2. In the Pop-ups pane, click Fields list > Select fields.
  3. Under Expressions, select the newly created Arcade expression and click Done.

The image below shows the missing numbers listed from a specified range through a pop-up.

The missing numbers are listed in the pop-up

Article ID: 000032685

Software:
  • ArcGIS Online
  • Portal for ArcGIS
  • ArcGIS Enterprise 11 0
  • ArcGIS Enterprise 11 1
  • ArcGIS Enterprise 11 3
  • ArcGIS Enterprise 11 2

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