<?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: Return a value depending on if record in related table matches parent table in ArcGIS Field Maps Questions</title>
    <link>https://community.esri.com/t5/arcgis-field-maps-questions/return-a-value-depending-on-if-record-in-related/m-p/1569156#M10152</link>
    <description>&lt;P&gt;Here is the finished code that works for me:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Load the related rows using the FeatureSetByName function
var related_rows = Filter(FeatureSetByName($map, "Valve Field Pressure"),"Parent_GlobalID = '" + $feature.GlobalID + "'")

// Get the latest survey (sorted by created_date DESC)
var latest_survey = First(OrderBy(related_rows, "created_date DESC"))

// Check if PSI fields are valid (parent)
if($feature.TargetPSI == null) {
    return "No Target PSI in Valve Layer"
}

// Check if PSI fields are valid (child)
if(latest_survey.InputPostValvePressure == null) {
    return "Not Surveyed Yet"
}

// Return good or bad depending on PSI
if(latest_survey.InputPostValvePressure == $feature.TargetPSI) {
    return "Good PSI"
}
return "Adjust Pressure - See PDF for Instructions"&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 17 Dec 2024 00:05:45 GMT</pubDate>
    <dc:creator>chill_gis_dude</dc:creator>
    <dc:date>2024-12-17T00:05:45Z</dc:date>
    <item>
      <title>Return a value depending on if record in related table matches parent table</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/return-a-value-depending-on-if-record-in-related/m-p/1568109#M10135</link>
      <description>&lt;P&gt;I would like to return the values, good or bad, depending on if a value of a field in the related table matches a value in a field in the parent table. The two values are pressure in PSI and I am using the field maps web designer. Here is my code so far below&lt;/P&gt;&lt;LI-CODE lang="python"&gt;// load the related rows, using the name of the relationship class
var related_rows = FeaturesetByRelationshipName($feature, "GIS.SDE.tbl_Valve_FieldPressure")

// get the latest survey
var latest_survey = First(OrderBy(related_rows, "created_date DESC"))

// return a default value if no survey was found
if(latest_survey == null) {
    return "Not surveyed yet"
}

// return good or bad depending on PSI
if(latest_survey.InputPostValvePressure == latest_survey.TargetPSI) {
    return "Good"
}
return "Bad"&lt;/LI-CODE&gt;&lt;P&gt;Essentially, surveyors are entering an input PSI in the related table, and then I want a calculated field in the parent layer to grab the latest survey's input PSI and compare it to a field in the parent layer called Target PSI which already has a value in it. If the value in input PSI matches Target PSI return good, if they don't match return bad.&lt;/P&gt;&lt;P&gt;The code seems to work in the web designer. but when I go in field maps to test it just says failed to calculate. Anyone have any idea?&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2024 20:34:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/return-a-value-depending-on-if-record-in-related/m-p/1568109#M10135</guid>
      <dc:creator>chill_gis_dude</dc:creator>
      <dc:date>2024-12-12T20:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: Return a value depending on if record in related table matches parent table</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/return-a-value-depending-on-if-record-in-related/m-p/1568858#M10148</link>
      <description>&lt;P&gt;Could be two things.&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; There was a bug for awhile with having a . in the relationship name when using&amp;nbsp;FeaturesetByRelationshipName. I thought it was fixed but seeing others post on it.&amp;nbsp; (Is your Field Maps up to date?)&amp;nbsp; &amp;nbsp;Try Filter(FeatureSetByName()) instead and see if that works.&lt;/P&gt;&lt;P&gt;2.&amp;nbsp; If you get nothing back from&amp;nbsp;FeaturesetByRelationshipName then&amp;nbsp;var latest_survey = First(OrderBy(related_rows, "created_date DESC")) will fail.&amp;nbsp; You should check if&amp;nbsp;related_rows is empty before calling First not after.&lt;/P&gt;&lt;P&gt;Hope that does it&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 14:43:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/return-a-value-depending-on-if-record-in-related/m-p/1568858#M10148</guid>
      <dc:creator>DougBrowning</dc:creator>
      <dc:date>2024-12-16T14:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: Return a value depending on if record in related table matches parent table</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/return-a-value-depending-on-if-record-in-related/m-p/1568903#M10149</link>
      <description>&lt;P&gt;Thank you Doug for your helpful comments. I've talked with others and it seems the . in the relationship name is still an issue in 11.2, which we are on. I did get it to work using the FeatureSetByName but it returns the latest related record of any feature rather than the one you interact with, so I am adding a filter where the parent id == child id. I'll post my code when I'm done.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 15:47:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/return-a-value-depending-on-if-record-in-related/m-p/1568903#M10149</guid>
      <dc:creator>chill_gis_dude</dc:creator>
      <dc:date>2024-12-16T15:47:14Z</dc:date>
    </item>
    <item>
      <title>Re: Return a value depending on if record in related table matches parent table</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/return-a-value-depending-on-if-record-in-related/m-p/1569156#M10152</link>
      <description>&lt;P&gt;Here is the finished code that works for me:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Load the related rows using the FeatureSetByName function
var related_rows = Filter(FeatureSetByName($map, "Valve Field Pressure"),"Parent_GlobalID = '" + $feature.GlobalID + "'")

// Get the latest survey (sorted by created_date DESC)
var latest_survey = First(OrderBy(related_rows, "created_date DESC"))

// Check if PSI fields are valid (parent)
if($feature.TargetPSI == null) {
    return "No Target PSI in Valve Layer"
}

// Check if PSI fields are valid (child)
if(latest_survey.InputPostValvePressure == null) {
    return "Not Surveyed Yet"
}

// Return good or bad depending on PSI
if(latest_survey.InputPostValvePressure == $feature.TargetPSI) {
    return "Good PSI"
}
return "Adjust Pressure - See PDF for Instructions"&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 17 Dec 2024 00:05:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/return-a-value-depending-on-if-record-in-related/m-p/1569156#M10152</guid>
      <dc:creator>chill_gis_dude</dc:creator>
      <dc:date>2024-12-17T00:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: Return a value depending on if record in related table matches parent table</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/return-a-value-depending-on-if-record-in-related/m-p/1569322#M10153</link>
      <description>&lt;P&gt;I would still check&amp;nbsp;related_rows for a count &amp;gt; 0 instead.&amp;nbsp; First() can fail on you here.&lt;/P&gt;&lt;P&gt;You also have 3 different return statements which would look better as elsif or something like that.&lt;/P&gt;&lt;P&gt;Also seems like this check should be first.&amp;nbsp; Why do a lookup if you may not need it.&amp;nbsp; Can get slow.&lt;/P&gt;&lt;P&gt;// Check if PSI fields are valid (parent)&lt;BR /&gt;if($feature.TargetPSI == null) {&lt;BR /&gt;return "No Target PSI in Valve Layer"&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2024 14:54:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/return-a-value-depending-on-if-record-in-related/m-p/1569322#M10153</guid>
      <dc:creator>DougBrowning</dc:creator>
      <dc:date>2024-12-17T14:54:21Z</dc:date>
    </item>
  </channel>
</rss>

