Select to view content in your preferred language

Arcade code - list result in alphabetical order

04-15-2024 09:34 PM
Labels (3)
New Contributor III

Hi Community,

This is probably a simple question but someone like myself who's knew into arcade coding and coding in general, I still struggle haha. I have done some research and thought this would work but I am still getting an error. Basically the code below pulls results from the layer 'National Reserve System' that overlays another layer called IBRA, and produces a percentage value of how much is overlaid/impacted. The code works but now I want to get the results to be listed in alphabetical order. I put in a code that I thought might do it (var sortlist = OrderBy(resultlist, 'Name ASC') but I get this result - Test execution error: Execution error - Invalid parameter. Verify test data.

I know it's probably an easy fix but any ideas of how to fix this would be greatly appreciated 🙂


var impact_areas = Intersects($feature, FeatureSetByName($map, 'National Reserve System', ['*'], true));
var total_impacted_area = 0;
var total_area = $feature.HECTARES; // Assuming 'HECTARES' is the field representing area in IBRA 7 Regions

var resultList = "";
// Coding line that I thought would list the results in alphabetical order
var sortlist = OrderBy(resultlist, 'Name ASC');

// Check if impact_areas is empty
if (Count(impact_areas) == 0) {
    resultList = "0%";
} else {
    for (var ia in impact_areas) {
        var capadName = ia['Name'];
        var capadArea = AreaGeodetic(Intersection($feature, ia), 'HECTARES');
        var capadPerc = Round((capadArea / total_area) * 100, 1);
        // Check if percentage is greater than or equal to 0.01%
        if (capadPerc >= 0.01) {
            // Concatenate each item with a bullet dot and newline
            var resultItem = "• " + capadName + ': ' + Text(capadPerc) + ' %' + TextFormatting.NewLine;
            resultList += resultItem;

            total_impacted_area += capadArea;

// Return the results with bullet points and handle the case of no overlap
if (IsEmpty(resultList)) {
    return "0%";
} else {
    return TextFormatting.NewLine + resultList;


0 Kudos
2 Replies
Occasional Contributor

Hi mtuffy,

As far as I Know, there is not sort function in Arcade, and if you want to do sort of an ArrayList you should write a custom script.

Here is a sample of sorting in Arcade,

var textArray = ["orange", "banana", "Apple", "kiwi", "Grapes", "avocado", "coco"];

function compareText(a, b) {
  if (Lower(a) < Lower(b)) { return -1; }
  if (Lower(a) > Lower(b)) { return 1; }
  return 0;

var sortedArray = Sort(textArray, compareText);

hope it helps
Amir Sarrafzadeh Arasi
0 Kudos
New Contributor III

Hi Amir,

Thanks for your response! I will have a play with the code today and see if I can get something to work 🙂

Thanks again for helping,


0 Kudos