<?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: Using Arcade to bring related table info into pop-up - so close! in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/using-arcade-to-bring-related-table-info-into-pop/m-p/1181255#M46362</link>
    <description>&lt;P&gt;Wonderful, thank you! I think the piece that I still don't understand is&amp;nbsp;&lt;/P&gt;&lt;P&gt;for (var inspection in inspections)&amp;nbsp;&lt;/P&gt;&lt;P&gt;because I haven't defined var inspection, but hey, it works!&lt;/P&gt;</description>
    <pubDate>Wed, 08 Jun 2022 20:22:13 GMT</pubDate>
    <dc:creator>FPGIS_FrancescaRohr</dc:creator>
    <dc:date>2022-06-08T20:22:13Z</dc:date>
    <item>
      <title>Using Arcade to bring related table info into pop-up - so close!</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/using-arcade-to-bring-related-table-info-into-pop/m-p/1180833#M46339</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a feature service of tree points with a related table of inspections (1:M). I would like the pop-up to display the inspection date for those trees that have been inspected (related table field: Inspected_Date) .&amp;nbsp;&lt;/P&gt;&lt;P&gt;The FeatureLayer/RelatedTable relationship is based on GlobalID/GUID but there is also matching data in the UNIQUE_ID/Unique_ID fields.&lt;/P&gt;&lt;P&gt;I have an Arcade expression that correctly returns 'No inspections' for those trees that have not been inspected. For the trees that have been inspected, the expression returns the same date '5/23/2022' for all trees instead of the actual inspection date.&lt;/P&gt;&lt;P&gt;What do I need to tweak to make it work?&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;var tbl = FeatureSetByName($datastore,"CALFIRE_UrbanForestry_Inspections", ['Unique_ID', 'Inspection_Date'])&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;var uniqueid = $feature["Unique_ID"]&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;var sql = "UNIQUE_ID = @uniqueid"&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Console(sql)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;var inspections = Filter(tbl, sql)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;var cnt = Count(inspections)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;var history = ""&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;if (cnt &amp;gt; 0) {&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;history = "inspections: " + cnt &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;for (var inspections in tbl) {&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;var insp_date = Text(inspections.Inspection_Date, 'MM/DD/YYYY')&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;history = "Inspected: " + insp_date&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;} else {&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;history = "No inspections"&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;return history&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All help is greatly appreciated,&lt;/P&gt;&lt;P&gt;Francesca&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2022 22:39:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/using-arcade-to-bring-related-table-info-into-pop/m-p/1180833#M46339</guid>
      <dc:creator>FPGIS_FrancescaRohr</dc:creator>
      <dc:date>2022-06-07T22:39:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using Arcade to bring related table info into pop-up - so close!</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/using-arcade-to-bring-related-table-info-into-pop/m-p/1180958#M46342</link>
      <description>&lt;P&gt;It's because you iterate over &lt;STRONG&gt;tbl&lt;/STRONG&gt;, not over the filtered &lt;STRONG&gt;inspections&lt;/STRONG&gt;. Your expressions returns the date of the last entry in the inspection table.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var tbl = FeatureSetByName($datastore,"TestPoints", ['UNIQUE_ID', 'Inspection_Date'])
var uniqueid = $feature["Unique_ID"]
var sql = "UNIQUE_ID= @uniqueid"
Console(sql)
// Filter by UNIQUE_ID and sort the result by date
var inspections = OrderBy(Filter(tbl, sql), "Inspection_Date")
var cnt = Count(inspections)
// return early if there are no inspections
if(cnt == 0) {
    return "No inspections"
}
// get all inspections in a list
var history = [
    `${cnt} inspections`
    ]
for (var inspection in inspections) {
    var insp_date = Text(inspection.Inspection_Date, 'MM/DD/YYYY')
    Push(history, `Inspected: ${insp_date}`)
}
// return the concatenated list
return Concatenate(history, TextFormatting.NewLine)&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1654675020589.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/42976i237EA892A6866D30/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1654675020589.png" alt="JohannesLindner_0-1654675020589.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you only want to return the latest inspection, you can do it like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var tbl = FeatureSetByName($datastore,"TestPoints", ['UNIQUE_ID', 'Inspection_Date'])
var uniqueid = $feature["Unique_ID"]
var sql = "UNIQUE_ID= @uniqueid"
Console(sql)
// Filter by UNIQUE_ID and sort the result by date DESCENDING
var inspections = OrderBy(Filter(tbl, sql), "Inspection_Date DESC")
var cnt = Count(inspections)
// return early if there are no inspections
if(cnt == 0) {
    return "No inspections"
}
// get the last inspection date
var insp_date = Text(First(inspections).Inspection_Date, 'MM/DD/YYYY')
var history = [
    `${cnt} inspections`,
    `Last inspection: ${insp_date}`
    ]
return Concatenate(history, TextFormatting.NewLine)&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_1-1654675172116.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/42977i8067A1FC1867C771/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_1-1654675172116.png" alt="JohannesLindner_1-1654675172116.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2022 08:01:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/using-arcade-to-bring-related-table-info-into-pop/m-p/1180958#M46342</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-06-08T08:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using Arcade to bring related table info into pop-up - so close!</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/using-arcade-to-bring-related-table-info-into-pop/m-p/1181255#M46362</link>
      <description>&lt;P&gt;Wonderful, thank you! I think the piece that I still don't understand is&amp;nbsp;&lt;/P&gt;&lt;P&gt;for (var inspection in inspections)&amp;nbsp;&lt;/P&gt;&lt;P&gt;because I haven't defined var inspection, but hey, it works!&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2022 20:22:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/using-arcade-to-bring-related-table-info-into-pop/m-p/1181255#M46362</guid>
      <dc:creator>FPGIS_FrancescaRohr</dc:creator>
      <dc:date>2022-06-08T20:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using Arcade to bring related table info into pop-up - so close!</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/using-arcade-to-bring-related-table-info-into-pop/m-p/1181367#M46370</link>
      <description>&lt;P&gt;You define inspection directly in the for loop declaration. That's what the var does: It creates a variable. It's a shortcut. You could also do it outside the loop. These two loops work exactly the same:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var arr = [1, 2, 3]

var i
for(i in arr) {
    Console(arr[i])
}

for(var j in arr) {
    Console(arr[j])
}&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 09 Jun 2022 06:40:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/using-arcade-to-bring-related-table-info-into-pop/m-p/1181367#M46370</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-06-09T06:40:09Z</dc:date>
    </item>
  </channel>
</rss>

