<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Arcade expression to sort an integer field array and return top 5 in ArcGIS Field Maps Questions</title>
    <link>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-expression-to-sort-an-integer-field-array/m-p/1602208#M10665</link>
    <description>&lt;P&gt;When I dropped that into Arcade playground it identified there was a missing comma somewhere around the Push function. Tried a few inserts without success., Where should it be placed?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BronwynRodgers1_0-1743663850573.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/129368i7F13346952180BDA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BronwynRodgers1_0-1743663850573.png" alt="BronwynRodgers1_0-1743663850573.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 03 Apr 2025 07:06:38 GMT</pubDate>
    <dc:creator>BronwynRodgers1</dc:creator>
    <dc:date>2025-04-03T07:06:38Z</dc:date>
    <item>
      <title>Arcade expression to sort an integer field array and return top 5</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-expression-to-sort-an-integer-field-array/m-p/1601705#M10654</link>
      <description>&lt;P&gt;I'm quite new to Arcade scripting and need some assistance, I have developed a Field Maps form to evaluate site suitability for tree cultivars. The trees have suitability scores 0-4 for a range of site characteristics. The scores are then totalled. I want to sort these scores descending and return the top 5 names and scores as a readable list.&lt;/P&gt;&lt;P&gt;I typed this query into Copilot along with the attached subset of my 50 tree cultivars and example scores, and received the following (also in an attached file), which does not work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;// Create an array of field names with their scores&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;var trees = [&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { "name": "Weraiti", "score": $feature.Weraiti },&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { "name": "Yeogi", "score": $feature.Yeogi },&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { "name": "Yunnan", "score": $feature.Yunnan },&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { "name": "Booth", "score": $feature.Booth },&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { "name": "Awanui", "score": $feature.Awanui },&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { "name": "Aegyptica", "score": $feature.Aegyptica },&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { "name": "Gigantea", "score": $feature.Gigantea },&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { "name": "Glenmark", "score": $feature.Glenmark }&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;];&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;// Sort the array by scores in descending order&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;var sortedTrees = Sort(trees, function(item1, item2) {&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return item2.score - item1.score;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;});&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;// Get the top 5 items&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;var topTrees = Slice(sortedTrees, 0, 5);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;// Create a readable list&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;var readableList = "";&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;for (var i = 0; i &amp;lt; Count(topTrees); i++) {&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; readableList += (i + 1) + ". " + topTrees[i].name + " - " + topTrees[i].score + TextFormatting.NewLine;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;return readableList;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;And when pasted into Arcade Playground shows where the error is.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BronwynRodgers1_0-1743576055692.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/129267iCE3991795F8103EA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BronwynRodgers1_0-1743576055692.png" alt="BronwynRodgers1_0-1743576055692.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;My deadline for this app is fast approaching so I would appreciate a reworked expression that I can apply to my complete tree array.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Apr 2025 06:58:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-expression-to-sort-an-integer-field-array/m-p/1601705#M10654</guid>
      <dc:creator>BronwynRodgers1</dc:creator>
      <dc:date>2025-04-02T06:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expression to sort an integer field array and return top 5</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-expression-to-sort-an-integer-field-array/m-p/1601758#M10656</link>
      <description>&lt;P&gt;Hey &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/895524"&gt;@BronwynRodgers1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRIKE&gt;Just from an initial look, and this could be incorrect as I'm going to throw this in my own testing, this all looks correct except for a single missing parenthesis here:&lt;/STRIKE&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="CodyPatterson_0-1743594506467.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/129279iDF701DCB17DF96B7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="CodyPatterson_0-1743594506467.png" alt="CodyPatterson_0-1743594506467.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRIKE&gt;Sort() should be something like this: var sortedTrees = Sort(trees, function(item1, item2))&lt;/STRIKE&gt;&lt;/P&gt;&lt;P&gt;After another look, I was confused at the break between the function declaration, what you have does look pretty good though, maybe consider mirroring what this function here in the documentation does, while also making sure all values are what you should expect:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var peopleArray = [{ 'NAME': 'Sam', 'AGE': 25 }, {'NAME': 'Bob', 'AGE': 27 },{ 'NAME': 'Emma', 'AGE': 24 }];
function compareAge(a,b){
  if (a['AGE']&amp;lt;b['AGE'])
    return -1;
  if (a['AGE']&amp;gt;b['AGE'])
    return 1;
  return 0;
}
return Sort(peopleArray, compareAge);
// returns '[{ 'AGE': 24, 'NAME': 'Emma' }, { 'AGE': 25, 'NAME': 'Sam' }, { 'AGE': 27, 'NAME': 'Bob' } ]'&lt;/LI-CODE&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/arcade/function-reference/array_functions/#sort" target="_blank"&gt;https://developers.arcgis.com/arcade/function-reference/array_functions/#sort&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Let me know if that works, I'm continuing my testing as well!&lt;/P&gt;&lt;P&gt;Cody&lt;/P&gt;</description>
      <pubDate>Wed, 02 Apr 2025 11:56:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-expression-to-sort-an-integer-field-array/m-p/1601758#M10656</guid>
      <dc:creator>CodyPatterson</dc:creator>
      <dc:date>2025-04-02T11:56:22Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expression to sort an integer field array and return top 5</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-expression-to-sort-an-integer-field-array/m-p/1601772#M10658</link>
      <description>&lt;P&gt;Another method is to make a simple featureset and use the orderby and top methods to get the top 5&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var Fields = [
	{ 'name':'TreeSpecies' , 'type': 'esriFieldTypeString' , 'length':50 },
	{ 'name':'Score' , 'type': 'esriFieldTypeInteger' },
	]

var TreeNames = {
	'Weraiti':0,
	'Yeogi':0,
	"Yunnan":0,
	"Booth":0,
	"Awanui":0,
	"Aegyptica":0,
	"Gigantea":0,
	"Glenmark":0
	}

Expects($feature,'*')
var Values = []
for( var N in TreeNames ){
	V = { 'TreeSpecies' : N , 'Score': $feature[ N ] 
	Push( Values , {'attributes': V )
	}
var TreeScores = {
	'fields' : Fields,
	'geometry':'',
	'features': Values
	}
TreeScores = FeatureSet(Text(TreeScores))
TreeScores = Top(OrderBy(TreeScores,'Score'+'Desc'),5)
var M = ''
for( var row in TreeScores){
	M = M +'${row.TreeSpecies} has ${row.Score}'+TextFormatting.NewLine
	}
Console( M )&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 02 Apr 2025 12:43:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-expression-to-sort-an-integer-field-array/m-p/1601772#M10658</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2025-04-02T12:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expression to sort an integer field array and return top 5</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-expression-to-sort-an-integer-field-array/m-p/1602208#M10665</link>
      <description>&lt;P&gt;When I dropped that into Arcade playground it identified there was a missing comma somewhere around the Push function. Tried a few inserts without success., Where should it be placed?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BronwynRodgers1_0-1743663850573.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/129368i7F13346952180BDA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BronwynRodgers1_0-1743663850573.png" alt="BronwynRodgers1_0-1743663850573.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 07:06:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-expression-to-sort-an-integer-field-array/m-p/1602208#M10665</guid>
      <dc:creator>BronwynRodgers1</dc:creator>
      <dc:date>2025-04-03T07:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expression to sort an integer field array and return top 5</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-expression-to-sort-an-integer-field-array/m-p/1602232#M10667</link>
      <description>&lt;P&gt;Hi Cody,&lt;/P&gt;&lt;P&gt;So I took that example from the documentation and adapted it to my situation:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;treeArray&lt;/SPAN&gt;&lt;SPAN&gt; = [{ &lt;/SPAN&gt;&lt;SPAN&gt;'NAME'&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;'Weraiti'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'SCORE'&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;$feature&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;Weraiti&lt;/SPAN&gt;&lt;SPAN&gt; }, {&lt;/SPAN&gt;&lt;SPAN&gt;'NAME'&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;'Yeogi'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'SCORE'&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;$feature&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;Yeogi&lt;/SPAN&gt;&lt;SPAN&gt; },{ &lt;/SPAN&gt;&lt;SPAN&gt;'NAME'&lt;/SPAN&gt;&lt;SPAN&gt;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SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;SPAN&gt;a&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;'SCORE'&lt;/SPAN&gt;&lt;SPAN&gt;]&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt;b&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;'SCORE'&lt;/SPAN&gt;&lt;SPAN&gt;])&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;return&lt;/SPAN&gt; &lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;return&lt;/SPAN&gt; &lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;return&lt;/SPAN&gt; &lt;SPAN&gt;Sort&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;treeArray&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;compareSCORE&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;The attached file is a screenshot of the result in the Field Maps mobile app - returned all, not sorted.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;BTW how do I insert the code into these posts with all the code lines, not just as text as I have done this time?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 03 Apr 2025 08:16:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-expression-to-sort-an-integer-field-array/m-p/1602232#M10667</guid>
      <dc:creator>BronwynRodgers1</dc:creator>
      <dc:date>2025-04-03T08:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expression to sort an integer field array and return top 5</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-expression-to-sort-an-integer-field-array/m-p/1602267#M10668</link>
      <description>&lt;P&gt;Sorry there was a script typo. I was using a different IDE outside of the Arcade and noticed that a couple of lines were missing a bracket.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var Fields = [
	{ 'name':'TreeSpecies' , 'type': 'esriFieldTypeString' , 'length':50 },
	{ 'name':'Score' , 'type': 'esriFieldTypeInteger' },
	]

var TreeNames = {
	'Weraiti':0,
	'Yeogi':0,
	"Yunnan":0,
	"Booth":0,
	"Awanui":0,
	"Aegyptica":0,
	"Gigantea":0,
	"Glenmark":0
	}

Expects($feature,'*')
var Values = []
for( var N in TreeNames ){
	var V = { 'TreeSpecies' : N , 'Score': $feature[ N ] }
	Push( Values , {'attributes': V } )
	}
var TreeScores = {
	'fields' : Fields,
	'geometry':'',
	'features': Values
	}
TreeScores = FeatureSet(Text(TreeScores))
TreeScores = Top(OrderBy(TreeScores,'Score'+'Desc'),5)
var M = ''
for( var row in TreeScores){
	M = M + Text(row.TreeSpecies) + ' has ' + Text(row.Score)+TextFormatting.NewLine
	}
Console( M )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;If you are using the arcade playground to test things then this code will need to be reconfigured to whatever test data your are trying to use.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 11:14:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-expression-to-sort-an-integer-field-array/m-p/1602267#M10668</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2025-04-03T11:14:22Z</dc:date>
    </item>
  </channel>
</rss>

