Select to view content in your preferred language

Arcade for loop returns multiple of same results

1240
11
12-07-2023 07:19 AM
ZachBodenner
MVP Regular Contributor

Hello,

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:

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}<br>
        <b>AccountNum: </b>${f.g2_AccountNumber}<br>
        <b>PID: </b>${f.g2_UB_PID}<br>
        <b>Meter #: </b>${f.g5_MeterNumber}<br>
				<b>Meter Type: </b>${f.m3_MeterType}<br>
        <b>Install Date: </b>${f.g5_DateInstalled}<br>
        <b>Serial: </b>${f.m3_SerialNumber}<br>
        <br>
        `
}

return { 
	type : 'text', 
	text : popupString
}

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:

ZachBodenner_0-1701962215270.png

 

However, running the expression above, only one of those two records is returned, and it is retuned twice:

ZachBodenner_1-1701962268810.png

 

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. 

0 Kudos
11 Replies
KenBuja
MVP Esteemed Contributor

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.

0 Kudos
ZachBodenner
MVP Regular Contributor

Confirmed, multiple duplicate records. 

ZachBodenner_0-1701980439548.png


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

0 Kudos