<?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 How to create an arcade expression to show most recent Related Table data. in ArcGIS Survey123 Questions</title>
    <link>https://community.esri.com/t5/arcgis-survey123-questions/how-to-create-an-arcade-expression-to-show-most/m-p/1030131#M32699</link>
    <description>&lt;P&gt;I have a geodatabase with a pump station layer and an inspection table related to the pump station layer with a one to many relationship.&amp;nbsp; I created a survey using the related table so new surveys simply add to the related inspection table.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a map with my pump station layer and related tables.&amp;nbsp; I created a custom URL in the popup to launch Survey123 to perform an inspection on the selected pump station.&amp;nbsp; The Custom URL passes the pump station ID to Survey123, then the user fills out the rest of the inspection. One of the inspection questions requires the user to write in the current water level.&amp;nbsp; The user has to monitor the change in water level, Which mean the user needs to be able to reference the water recorded in the previous inspection for that pump station.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to add that information to my custom url so the most recently recorded water level for a pump station is simply passed to a field specific in the Survey.&amp;nbsp; The user than can see the previous water level, enter the current water level, and the next survey question automatically calculate the change in water level.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I planned to create a custom arcade expression to reference the most recent water level for each pump station, but I'm unsure how to write the expression, and need some guidance.&amp;nbsp; I've done a lot of research and testing and I'm worried this just isn't possible.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1108"&gt;@XanderBakker&lt;/a&gt;&amp;nbsp; &amp;nbsp;Added your name since you seem to be the Arcade Scripting King &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Feb 2021 18:56:58 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2021-02-24T18:56:58Z</dc:date>
    <item>
      <title>How to create an arcade expression to show most recent Related Table data.</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/how-to-create-an-arcade-expression-to-show-most/m-p/1030131#M32699</link>
      <description>&lt;P&gt;I have a geodatabase with a pump station layer and an inspection table related to the pump station layer with a one to many relationship.&amp;nbsp; I created a survey using the related table so new surveys simply add to the related inspection table.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a map with my pump station layer and related tables.&amp;nbsp; I created a custom URL in the popup to launch Survey123 to perform an inspection on the selected pump station.&amp;nbsp; The Custom URL passes the pump station ID to Survey123, then the user fills out the rest of the inspection. One of the inspection questions requires the user to write in the current water level.&amp;nbsp; The user has to monitor the change in water level, Which mean the user needs to be able to reference the water recorded in the previous inspection for that pump station.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to add that information to my custom url so the most recently recorded water level for a pump station is simply passed to a field specific in the Survey.&amp;nbsp; The user than can see the previous water level, enter the current water level, and the next survey question automatically calculate the change in water level.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I planned to create a custom arcade expression to reference the most recent water level for each pump station, but I'm unsure how to write the expression, and need some guidance.&amp;nbsp; I've done a lot of research and testing and I'm worried this just isn't possible.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1108"&gt;@XanderBakker&lt;/a&gt;&amp;nbsp; &amp;nbsp;Added your name since you seem to be the Arcade Scripting King &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 18:56:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/how-to-create-an-arcade-expression-to-show-most/m-p/1030131#M32699</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-02-24T18:56:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an arcade expression to show most recent Related Table data.</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/how-to-create-an-arcade-expression-to-show-most/m-p/1030160#M32705</link>
      <description>&lt;P&gt;First part is to go grab the matching records from the other layer.&amp;nbsp; This is FeatureSet - can use by name or by relationship name if you have one.&lt;/P&gt;&lt;P&gt;var sql = "PointID = '" + $feature.PointID + "'";&lt;BR /&gt;var tbl = Filter(FeatureSetByName($map,"Points", ["*"], false), sql);&lt;/P&gt;&lt;P&gt;Then you can grab the first. Or do a sort, max etc.&lt;/P&gt;&lt;P&gt;return First(tbl).DesignLat&lt;/P&gt;&lt;P&gt;Or loop through them and/ or sort.&lt;/P&gt;&lt;P&gt;This example is pattern matching&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var sql = "PlotKey = '" + $feature.PlotKey + "'";
var tbl = Filter(FeatureSetByName($map,"LPI"), sql);

var txt = ''
for (var f in OrderBy(tbl,"LineNumber")) {
    txt = txt + f.LineNumber + ' '
}
txt = Left(txt,Count(txt)-1)
if (txt != '1 2 3') {
    return "\n----LPI Line Number Issue! Found: " + txt
}
else {
    return ''
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use it a lot, works great.&amp;nbsp; Note FeatureSet does not work in Collector but does in the new field maps.&lt;/P&gt;&lt;P&gt;Hope that helps&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 19:41:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/how-to-create-an-arcade-expression-to-show-most/m-p/1030160#M32705</guid>
      <dc:creator>DougBrowning</dc:creator>
      <dc:date>2021-02-24T19:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an arcade expression to show most recent Related Table data.</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/how-to-create-an-arcade-expression-to-show-most/m-p/1030179#M32710</link>
      <description>&lt;P&gt;Thank you so much for your quick help on this!!&amp;nbsp; &amp;nbsp;Bear with me, still confused on things!&amp;nbsp; I'm unsure of what I should swap out where in your example script and how to alter it to fit my needs.&amp;nbsp; This is what I have so far and I'm not sure where to go from here.&amp;nbsp; I apologize, I tried to read through the arcade logic documentation and just can't seem to wrap my brain around it.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Also I don't understand the reasoning between the empty quotes ' '.&amp;nbsp; I tried googling it to educate myself but couldn't immediately find anything to explain it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;FACILITYID is the field I use to relate the table to the pump stations&lt;BR /&gt;REPDATE is the inspection date&lt;BR /&gt;H2OLEV is the field I'm trying to list the most recent recorded value for each pump station.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var sql = "FACILITYID = '"+$feature.FACILITYID + "'";
var tbl = Filter(FeatureSetByName($map,"pumpstation_gdb - PumpStationinspection"), sql)

var txt = ''
for (var f in OrderBy(tbl, 'REPDATE DESC')) {
    txt = txt + f.REPDATE + ''&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1108"&gt;@XanderBakker&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 20:34:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/how-to-create-an-arcade-expression-to-show-most/m-p/1030179#M32710</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-02-24T20:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an arcade expression to show most recent Related Table data.</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/how-to-create-an-arcade-expression-to-show-most/m-p/1030187#M32711</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var sql = "FACILITYID = '"+$feature.FACILITYID + "'";
var tbl = Filter(FeatureSetByName($map,"pumpstation_gdb - PumpStationinspection"), sql)

return First(OrderBy(tbl, 'REPDATE DESC')).H2OLEV&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 24 Feb 2021 20:34:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/how-to-create-an-arcade-expression-to-show-most/m-p/1030187#M32711</guid>
      <dc:creator>DougBrowning</dc:creator>
      <dc:date>2021-02-24T20:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an arcade expression to show most recent Related Table data.</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/how-to-create-an-arcade-expression-to-show-most/m-p/1030194#M32715</link>
      <description>&lt;P&gt;What you wrote makes logical sense to me.&amp;nbsp; But when I test it, I get an error "&lt;SPAN&gt;Runtime Error: Cannot call member method on null.&amp;nbsp;H2OLEV"&amp;nbsp; Does this mean I need to tell it to ignore nulls? Or do nothing if there are nulls?&amp;nbsp; This is a brand new inspection table, I only have one inspection record for one pump station in there that is just tester data.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 20:44:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/how-to-create-an-arcade-expression-to-show-most/m-p/1030194#M32715</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-02-24T20:44:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an arcade expression to show most recent Related Table data.</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/how-to-create-an-arcade-expression-to-show-most/m-p/1030202#M32716</link>
      <description>&lt;P&gt;Well yea you gotta test on some real data. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but you could stick in a if&lt;/P&gt;&lt;P&gt;if count(tbl) == 0&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;return "no records found"&lt;/P&gt;&lt;P&gt;else&lt;/P&gt;&lt;P&gt;return First(OrderBy(tbl, 'REPDATE DESC')).H2OLEV&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 21:05:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/how-to-create-an-arcade-expression-to-show-most/m-p/1030202#M32716</guid>
      <dc:creator>DougBrowning</dc:creator>
      <dc:date>2021-02-24T21:05:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an arcade expression to show most recent Related Table data.</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/how-to-create-an-arcade-expression-to-show-most/m-p/1030220#M32719</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/16421"&gt;@DougBrowning&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You, Sir are a lifesaver! Thank you so much for your help!!!&amp;nbsp; I got it to work!&amp;nbsp; &amp;nbsp;I see why you have "MVP" next to your name.&amp;nbsp;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is my final code if anyone else needs to use it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var sql = "FACILITYID = '"+$feature.FACILITYID + "'";
var tbl = Filter(FeatureSetByName($map,"pumpstation_gdb - PumpStationinspection"), sql)

if ((Count(tbl))==0) {
    return "no records found"
}
else {
    return First(OrderBy(tbl, 'REPDATE DESC')).H2OLEV
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 21:48:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/how-to-create-an-arcade-expression-to-show-most/m-p/1030220#M32719</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-02-24T21:48:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an arcade expression to show most recent Related Table data.</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/how-to-create-an-arcade-expression-to-show-most/m-p/1225922#M45625</link>
      <description>&lt;P&gt;How would you suggest getting the entire inspection record? For some reason, whenever I use the First() function, no records show up.&lt;/P&gt;&lt;P&gt;I tried a loop function, but it doesn't seem to be working:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var sql = "GUID = '"+$feature.GlobalID + "'";
var tbl = Filter(FeatureSetByName($datastore, "Pruning Maintenance"), sql)

if ((Count(tbl))==0) {
return "No Inspection Data to Show"
}
else {
var output = ''
for (var record in OrderBy(tbl, 'InspectionDate DESC')){
output += Text(First(record.InspectionDate), 'MM DD YYYY') + TextFormatting.NewLine +
First(record.RiskRating) + TextFormatting.NewLine + First(record.Notes)
}
return output
}&lt;/LI-CODE&gt;&lt;P&gt;It also doesn't work when I do:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;for (var record in First(OrderBy(tbl, 'InspectionDate DESC')){&lt;/LI-CODE&gt;&lt;P&gt;Are there any workarounds you can think of? As soon as I delete the "First()", the pop-up magically works. But that defeats the purpose because I want the most recent record.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 21:22:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/how-to-create-an-arcade-expression-to-show-most/m-p/1225922#M45625</guid>
      <dc:creator>dommybo123</dc:creator>
      <dc:date>2022-10-26T21:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an arcade expression to show most recent Related Table data.</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/how-to-create-an-arcade-expression-to-show-most/m-p/1225941#M45627</link>
      <description>&lt;P&gt;If you just want the first one why are you looping?&lt;/P&gt;&lt;P&gt;I think this would work&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var sql = "GUID = '"+$feature.GlobalID + "'";
var tbl = Filter(FeatureSetByName($datastore, "Pruning Maintenance"), sql)

if ((Count(tbl))==0) {
return "No Inspection Data to Show"
}
else {
var output = ''
var tblOrder = OrderBy(tbl, 'InspectionDate DESC')
output = Text(First(tblOrder.InspectionDate), 'MM DD YYYY') + TextFormatting.NewLine +
First(tblOrder.RiskRating) + TextFormatting.NewLine + First(tblOrder.Notes)

return output
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp; Try that&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 21:45:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/how-to-create-an-arcade-expression-to-show-most/m-p/1225941#M45627</guid>
      <dc:creator>DougBrowning</dc:creator>
      <dc:date>2022-10-26T21:45:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an arcade expression to show most recent Related Table data.</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/how-to-create-an-arcade-expression-to-show-most/m-p/1559274#M60097</link>
      <description>&lt;P&gt;Can you please explain how to set this up?? I've been trying for hours.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2024 17:51:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/how-to-create-an-arcade-expression-to-show-most/m-p/1559274#M60097</guid>
      <dc:creator>Krocha</dc:creator>
      <dc:date>2024-11-15T17:51:43Z</dc:date>
    </item>
  </channel>
</rss>

