<?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 for loop returns multiple of same results in ArcGIS Enterprise Questions</title>
    <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358233#M37916</link>
    <description>&lt;P&gt;Throw in some Console commands.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var parcelPID = $feature.PID;
Console(`Getting related forms for Parcel PID ${parcelPID}`)

var relatedForms = FeatureSetByName($map, "UBTEST - Epgdb.engineering.UB test2")
var filterStatement = "g2_UB_PID = @parcelPID"

var ubRecords = Filter(relatedForms, filterStatement)
Console(`Identified ${Count(ubRecords)} related forms`)

var ubRecordsSorted = OrderBy(ubRecords, 'RowNumber DESC')

for (var f in ubRecordsSorted) {
  Console(`Getting attributes for Row Number ${f.Rownumber}`)
}&lt;/LI-CODE&gt;&lt;P&gt;What do you see in the Console tab?&lt;/P&gt;</description>
    <pubDate>Thu, 07 Dec 2023 19:54:44 GMT</pubDate>
    <dc:creator>jcarlson</dc:creator>
    <dc:date>2023-12-07T19:54:44Z</dc:date>
    <item>
      <title>Arcade for loop returns multiple of same results</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1357988#M37903</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have an Arcade expression that has worked perfectly in other applications but is returning some odd results after I repurposed it in another map. Here's the expression:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var parcelPID = $feature.PID;
var relatedForms = FeatureSetByName($map, "UBTEST - Epgdb.engineering.UB test2")

var filterStatement = "g2_UB_PID = @parcelPID"

var ubRecords = Filter(relatedForms, filterStatement)
var ubRecordsSorted = OrderBy(ubRecords, 'RowNumber DESC')

var popupString = ''

for (var f in ubRecordsSorted){
    popupString += 
        `${f.Rownumber}&amp;lt;br&amp;gt;
        &amp;lt;b&amp;gt;AccountNum: &amp;lt;/b&amp;gt;${f.g2_AccountNumber}&amp;lt;br&amp;gt;
        &amp;lt;b&amp;gt;PID: &amp;lt;/b&amp;gt;${f.g2_UB_PID}&amp;lt;br&amp;gt;
        &amp;lt;b&amp;gt;Meter #: &amp;lt;/b&amp;gt;${f.g5_MeterNumber}&amp;lt;br&amp;gt;
				&amp;lt;b&amp;gt;Meter Type: &amp;lt;/b&amp;gt;${f.m3_MeterType}&amp;lt;br&amp;gt;
        &amp;lt;b&amp;gt;Install Date: &amp;lt;/b&amp;gt;${f.g5_DateInstalled}&amp;lt;br&amp;gt;
        &amp;lt;b&amp;gt;Serial: &amp;lt;/b&amp;gt;${f.m3_SerialNumber}&amp;lt;br&amp;gt;
        &amp;lt;br&amp;gt;
        `
}

return { 
	type : 'text', 
	text : popupString
}&lt;/LI-CODE&gt;&lt;P&gt;What it should do is search the table UB_Test_2 for all the rows that have the same g2_UB_PID and return meter information. Here's an example of the test 2 table. The identified parcel is the parent feature, and the two records shown in the table both have the same PID:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ZachBodenner_0-1701962215270.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/88295iEF04925EF767C794/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ZachBodenner_0-1701962215270.png" alt="ZachBodenner_0-1701962215270.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, running the expression above, only one of those two records is returned, and it is retuned twice:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ZachBodenner_1-1701962268810.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/88296i84AA8BFA53BF886D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ZachBodenner_1-1701962268810.png" alt="ZachBodenner_1-1701962268810.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This persists across all features, where the number of possible related records is returned, but only information from one of the records populates all the returns. As I mentioned, essentially this same expression (different datasets and just different fields used in the filter and return, with the same expression structure) works just fine.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 15:19:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1357988#M37903</guid>
      <dc:creator>ZachBodenner</dc:creator>
      <dc:date>2023-12-07T15:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade for loop returns multiple of same results</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358102#M37905</link>
      <description>&lt;P&gt;Does it do the same thing if you use FeatureSetByRelationshipName? Or is there not a real relationship in place, just a shared field?&lt;/P&gt;&lt;P&gt;Instead of constantly appending to a single string, try creating an array and using Concatenate:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var popup_arr = []

for (var f in ubRecordsSorted) {
  Push(
    popup_arr,
    `your string goes here`
  )
}

return {
  type: 'text',
  text: Concatenate(popup_arr, '&amp;lt;br&amp;gt;')
}&lt;/LI-CODE&gt;&lt;P&gt;Any change?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 17:16:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358102#M37905</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2023-12-07T17:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade for loop returns multiple of same results</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358150#M37908</link>
      <description>&lt;P&gt;Not a real relationship, just a shared field. Curiously your expression did the same thing, but with a different row, even though I left the Sort variable alone:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var parcelPID = $feature.PID;
var relatedForms = FeatureSetByName($map, "UBTEST - Epgdb.engineering.UB test2")

var filterStatement = "g2_UB_PID = @parcelPID"

var ubRecords = Filter(relatedForms, filterStatement)
var ubRecordsSorted = OrderBy(ubRecords, 'RowNumber DESC')

//var popupString = ''

/*for (var f in ubRecordsSorted){
    popupString += 
        `${f.Rownumber}&amp;lt;br&amp;gt;
        &amp;lt;b&amp;gt;AccountNum: &amp;lt;/b&amp;gt;${f.g2_AccountNumber}&amp;lt;br&amp;gt;
        &amp;lt;b&amp;gt;PID: &amp;lt;/b&amp;gt;${f.g2_UB_PID}&amp;lt;br&amp;gt;
        &amp;lt;b&amp;gt;Meter #: &amp;lt;/b&amp;gt;${f.g5_MeterNumber}&amp;lt;br&amp;gt;
				&amp;lt;b&amp;gt;Meter Type: &amp;lt;/b&amp;gt;${f.m3_MeterType}&amp;lt;br&amp;gt;
        &amp;lt;b&amp;gt;Install Date: &amp;lt;/b&amp;gt;${f.g5_DateInstalled}&amp;lt;br&amp;gt;
        &amp;lt;b&amp;gt;Serial: &amp;lt;/b&amp;gt;${f.m3_SerialNumber}&amp;lt;br&amp;gt;
        &amp;lt;br&amp;gt;
        `
}*/
var popup_arr = []

for (var f in ubRecordsSorted) {
  Push(
    popup_arr,
    `${f.Rownumber}&amp;lt;br&amp;gt;
        &amp;lt;b&amp;gt;AccountNum: &amp;lt;/b&amp;gt;${f.g2_AccountNumber}&amp;lt;br&amp;gt;
        &amp;lt;b&amp;gt;PID: &amp;lt;/b&amp;gt;${f.g2_UB_PID}&amp;lt;br&amp;gt;
        &amp;lt;b&amp;gt;Meter #: &amp;lt;/b&amp;gt;${f.g5_MeterNumber}&amp;lt;br&amp;gt;
				&amp;lt;b&amp;gt;Meter Type: &amp;lt;/b&amp;gt;${f.m3_MeterType}&amp;lt;br&amp;gt;
        &amp;lt;b&amp;gt;Install Date: &amp;lt;/b&amp;gt;${f.g5_DateInstalled}&amp;lt;br&amp;gt;
        &amp;lt;b&amp;gt;Serial: &amp;lt;/b&amp;gt;${f.m3_SerialNumber}&amp;lt;br&amp;gt;
        &amp;lt;br&amp;gt;`
  )
}
return {
  type: 'text',
  text: Concatenate(popup_arr, '&amp;lt;br&amp;gt;')
}



&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ZachBodenner_0-1701970744849.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/88379i93E9DCF4DF377E0C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ZachBodenner_0-1701970744849.png" alt="ZachBodenner_0-1701970744849.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 17:39:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358150#M37908</guid>
      <dc:creator>ZachBodenner</dc:creator>
      <dc:date>2023-12-07T17:39:10Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade for loop returns multiple of same results</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358201#M37912</link>
      <description>&lt;P&gt;What do you see if you put in "return ubRecordsSorted" at line 8 and run this in the editor? Do you get the expected records?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 19:04:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358201#M37912</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2023-12-07T19:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade for loop returns multiple of same results</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358208#M37914</link>
      <description>&lt;P&gt;No, nothing in the result at all&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ZachBodenner_0-1701976331486.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/88395i355C4641285DC251/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ZachBodenner_0-1701976331486.png" alt="ZachBodenner_0-1701976331486.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 19:12:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358208#M37914</guid>
      <dc:creator>ZachBodenner</dc:creator>
      <dc:date>2023-12-07T19:12:17Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade for loop returns multiple of same results</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358233#M37916</link>
      <description>&lt;P&gt;Throw in some Console commands.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var parcelPID = $feature.PID;
Console(`Getting related forms for Parcel PID ${parcelPID}`)

var relatedForms = FeatureSetByName($map, "UBTEST - Epgdb.engineering.UB test2")
var filterStatement = "g2_UB_PID = @parcelPID"

var ubRecords = Filter(relatedForms, filterStatement)
Console(`Identified ${Count(ubRecords)} related forms`)

var ubRecordsSorted = OrderBy(ubRecords, 'RowNumber DESC')

for (var f in ubRecordsSorted) {
  Console(`Getting attributes for Row Number ${f.Rownumber}`)
}&lt;/LI-CODE&gt;&lt;P&gt;What do you see in the Console tab?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 19:54:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358233#M37916</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2023-12-07T19:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade for loop returns multiple of same results</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358240#M37917</link>
      <description>&lt;P&gt;I did have a couple tries at the console and using your expression there, got a somewhat unhelpful response of :&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Getting related forms for Parcel PID 3411622340001&lt;/P&gt;&lt;P&gt;Identified 0 related forms&lt;BR /&gt;&lt;BR /&gt;That does make sense for that particular PID, but is a little unhelpful to test whether or not the code is working. There isn't a way to specify the record that the Arcade element uses to test is there?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 19:59:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358240#M37917</guid>
      <dc:creator>ZachBodenner</dc:creator>
      <dc:date>2023-12-07T19:59:02Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade for loop returns multiple of same results</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358243#M37918</link>
      <description>&lt;P&gt;Can you run it in the code editor? This will show the returned FeatureSet and the console items that Josh also suggested&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="editor.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/88404i6AFF03E48C493E4A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="editor.png" alt="editor.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;You might have to put in a specific parcelPID to test it&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var parcelPID = "01824000034"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 20:03:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358243#M37918</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2023-12-07T20:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade for loop returns multiple of same results</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358249#M37919</link>
      <description>&lt;P&gt;Ah yeah good idea on strong-arming the variable. But it does appear that it just wants to return identical rows:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var parcelPID = '1811622110028';
Console(`Getting related forms for Parcel PID ${parcelPID}`)

var relatedForms = FeatureSetByName($map, "UBTEST - Epgdb.engineering.UB test2")
var filterStatement = "g2_UB_PID = @parcelPID"

var ubRecords = Filter(relatedForms, filterStatement)
Console(`Identified ${Count(ubRecords)} related forms`)

var ubRecordsSorted = OrderBy(ubRecords, 'RowNumber DESC')

for (var f in ubRecordsSorted) {
  Console(`Getting attributes for Row Number ${f.Rownumber}`)
}&lt;/LI-CODE&gt;&lt;P&gt;Returns:&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;Getting related forms for Parcel PID 1811622110028&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;Identified 3 related forms&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;Getting attributes for Row Number 2150&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;Getting attributes for Row Number 2150&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;Getting attributes for Row Number 2150&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 20:08:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358249#M37919</guid>
      <dc:creator>ZachBodenner</dc:creator>
      <dc:date>2023-12-07T20:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade for loop returns multiple of same results</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358253#M37920</link>
      <description>&lt;P&gt;The next step it to to see what the ubRecordsSorted FS contains. Put in a return statment on line 11 and see if you're getting the same records multiple times.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 20:15:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358253#M37920</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2023-12-07T20:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade for loop returns multiple of same results</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358255#M37921</link>
      <description>&lt;P&gt;If you're working with popups, it tends to pick something in your map extent.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 20:16:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358255#M37921</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2023-12-07T20:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade for loop returns multiple of same results</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358258#M37922</link>
      <description>&lt;P&gt;Confirmed, multiple duplicate records.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ZachBodenner_0-1701980439548.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/88407i2308E07956F7A7F2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ZachBodenner_0-1701980439548.png" alt="ZachBodenner_0-1701980439548.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;My guess it has something to do with the way the data is constructed. The UB table is a SQL view matching up two other tables, but if that were the case, it seems weird that I should be able to open the table and see different records&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 20:21:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/arcade-for-loop-returns-multiple-of-same-results/m-p/1358258#M37922</guid>
      <dc:creator>ZachBodenner</dc:creator>
      <dc:date>2023-12-07T20:21:41Z</dc:date>
    </item>
  </channel>
</rss>

