<?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 Attribute rule to update parent attribute from most recent child record in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/attribute-rule-to-update-parent-attribute-from/m-p/1608971#M1749</link>
    <description>&lt;P&gt;Hi - I would love some help please. I'm trying to write an attribute rule on a relationship class that will update an attribute on the parent record if the most recent child record is updated. The parent class is sampling sites and the child class is samples. So if an attribute on the most recent sample is set (Public_sample_date attribute), then the attribute on the site itself should be updated too. But I'm getting an error....&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;I am getting this error...&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="johnchewitt77_0-1745513357583.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/130925i381EB376B3CAC445/image-size/medium?v=v2&amp;amp;px=400" role="button" title="johnchewitt77_0-1745513357583.png" alt="johnchewitt77_0-1745513357583.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is below...&lt;/P&gt;&lt;P&gt;//Check if the updated Sample Record is valid&lt;BR /&gt;if ($feature.invalid_result == 'Yes') {&lt;BR /&gt;return;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Get the parent feature (should be just one)&lt;BR /&gt;var parent = First(FeatureSetByRelationshipName($feature, "Bathing_Water_Sites_SampleResults",["water_quality_indicator"], false));&lt;/P&gt;&lt;P&gt;// Exit if no parent found&lt;BR /&gt;if (IsEmpty(parent)) {&lt;BR /&gt;return;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Get all children related to that parent&lt;BR /&gt;var children = FeatureSetByRelationshipName(parent, "Bathing_Water_Sites_SampleResults",["Public_sample_date","water_quality_indicator"], false);&lt;/P&gt;&lt;P&gt;// Initialize most recent timestamp and result&lt;BR /&gt;var latestDate = Date(1900, 1, 1); // Arbitrary old date&lt;BR /&gt;var latestWQI = null;&lt;BR /&gt;var thisfeaturedate = $feature.Public_sample_date&lt;/P&gt;&lt;P&gt;// Loop through children to find the most recently updated one&lt;BR /&gt;for (var child in children) {&lt;BR /&gt;if (!IsEmpty(child.Public_sample_date) &amp;amp;&amp;amp; child.Public_sample_date &amp;gt; latestDate) {&lt;BR /&gt;latestDate = child.Public_sample_date;&lt;BR /&gt;latestWQI = child.water_quality_indicator;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Exit if the updated feature is not the latest one&lt;BR /&gt;if (thisfeaturedate &amp;lt; latestDate) {&lt;BR /&gt;return;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Proceed if parent exists&lt;BR /&gt;if (!IsEmpty(parent)) {&lt;BR /&gt;// Update the parent's water_quality_indicator with the water_quality_indicator of the most recent sample record&lt;BR /&gt;return {&lt;BR /&gt;'edit': [{&lt;BR /&gt;'className': 'Bathing_Water_Sites',&lt;BR /&gt;'updates': [{&lt;BR /&gt;'objectID': parent.OBJECTID,&lt;BR /&gt;'attributes': {&lt;BR /&gt;'water_quality_indicator': latestWQI&lt;BR /&gt;}&lt;BR /&gt;}]&lt;BR /&gt;}]&lt;BR /&gt;};&lt;BR /&gt;}&lt;/P&gt;</description>
    <pubDate>Thu, 24 Apr 2025 19:52:27 GMT</pubDate>
    <dc:creator>johnchewitt77</dc:creator>
    <dc:date>2025-04-24T19:52:27Z</dc:date>
    <item>
      <title>Attribute rule to update parent attribute from most recent child record</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/attribute-rule-to-update-parent-attribute-from/m-p/1608971#M1749</link>
      <description>&lt;P&gt;Hi - I would love some help please. I'm trying to write an attribute rule on a relationship class that will update an attribute on the parent record if the most recent child record is updated. The parent class is sampling sites and the child class is samples. So if an attribute on the most recent sample is set (Public_sample_date attribute), then the attribute on the site itself should be updated too. But I'm getting an error....&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;I am getting this error...&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="johnchewitt77_0-1745513357583.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/130925i381EB376B3CAC445/image-size/medium?v=v2&amp;amp;px=400" role="button" title="johnchewitt77_0-1745513357583.png" alt="johnchewitt77_0-1745513357583.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is below...&lt;/P&gt;&lt;P&gt;//Check if the updated Sample Record is valid&lt;BR /&gt;if ($feature.invalid_result == 'Yes') {&lt;BR /&gt;return;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Get the parent feature (should be just one)&lt;BR /&gt;var parent = First(FeatureSetByRelationshipName($feature, "Bathing_Water_Sites_SampleResults",["water_quality_indicator"], false));&lt;/P&gt;&lt;P&gt;// Exit if no parent found&lt;BR /&gt;if (IsEmpty(parent)) {&lt;BR /&gt;return;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Get all children related to that parent&lt;BR /&gt;var children = FeatureSetByRelationshipName(parent, "Bathing_Water_Sites_SampleResults",["Public_sample_date","water_quality_indicator"], false);&lt;/P&gt;&lt;P&gt;// Initialize most recent timestamp and result&lt;BR /&gt;var latestDate = Date(1900, 1, 1); // Arbitrary old date&lt;BR /&gt;var latestWQI = null;&lt;BR /&gt;var thisfeaturedate = $feature.Public_sample_date&lt;/P&gt;&lt;P&gt;// Loop through children to find the most recently updated one&lt;BR /&gt;for (var child in children) {&lt;BR /&gt;if (!IsEmpty(child.Public_sample_date) &amp;amp;&amp;amp; child.Public_sample_date &amp;gt; latestDate) {&lt;BR /&gt;latestDate = child.Public_sample_date;&lt;BR /&gt;latestWQI = child.water_quality_indicator;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Exit if the updated feature is not the latest one&lt;BR /&gt;if (thisfeaturedate &amp;lt; latestDate) {&lt;BR /&gt;return;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Proceed if parent exists&lt;BR /&gt;if (!IsEmpty(parent)) {&lt;BR /&gt;// Update the parent's water_quality_indicator with the water_quality_indicator of the most recent sample record&lt;BR /&gt;return {&lt;BR /&gt;'edit': [{&lt;BR /&gt;'className': 'Bathing_Water_Sites',&lt;BR /&gt;'updates': [{&lt;BR /&gt;'objectID': parent.OBJECTID,&lt;BR /&gt;'attributes': {&lt;BR /&gt;'water_quality_indicator': latestWQI&lt;BR /&gt;}&lt;BR /&gt;}]&lt;BR /&gt;}]&lt;BR /&gt;};&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Thu, 24 Apr 2025 19:52:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/attribute-rule-to-update-parent-attribute-from/m-p/1608971#M1749</guid>
      <dc:creator>johnchewitt77</dc:creator>
      <dc:date>2025-04-24T19:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: Attribute rule to update parent attribute from most recent child record</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/attribute-rule-to-update-parent-attribute-from/m-p/1609040#M1750</link>
      <description>&lt;P&gt;I think your listing missed the line where you grab the child's parent, but either way: that error is a sign that you have a parent to child update going on — either from an attribute rule on the parent or a composite relationship class — that retriggers the child, which retriggers the parent, and so on. Check what you have going on in the parent and look for potential loops. In some cases you can fix this by comparing fields in the &lt;FONT face="courier new,courier"&gt;$feature&lt;/FONT&gt; with matching fields in the &lt;FONT face="courier new,courier"&gt;$originalfeature&lt;/FONT&gt; and returning early if there were no changes.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Apr 2025 19:47:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/attribute-rule-to-update-parent-attribute-from/m-p/1609040#M1750</guid>
      <dc:creator>DavidSolari</dc:creator>
      <dc:date>2025-04-24T19:47:32Z</dc:date>
    </item>
    <item>
      <title>Re: Attribute rule to update parent attribute from most recent child record</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/attribute-rule-to-update-parent-attribute-from/m-p/1609042#M1751</link>
      <description>&lt;P&gt;Hi David - I really appreciate the reply, thanks a lot. You were right, I'd omitted the first few lines by mistake so they are now added. If it helps, I commented out the last part that updates the attributes and the code worked i.e. it does populate the&amp;nbsp;&lt;SPAN&gt;latestWQI&amp;nbsp;value, so I'm guessing the problem is with the last bit that updates the parent attribute.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Apr 2025 19:55:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/attribute-rule-to-update-parent-attribute-from/m-p/1609042#M1751</guid>
      <dc:creator>johnchewitt77</dc:creator>
      <dc:date>2025-04-24T19:55:40Z</dc:date>
    </item>
  </channel>
</rss>

