HOW TO
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.
var range = []; for (var i = 1; i <= 20; i++) { Push(range, i); }
var features = FeaturesetByName($map, "<layerName>", ["<fieldName>"]);
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; }
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; }
The image below shows the missing numbers listed from a specified range through a pop-up.
Get help from ArcGIS experts
Download the Esri Support App