<?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 When Multiple Child Records Exist, How to Carry Over Field Value of MOST RECENT Record to Parent Field in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/when-multiple-child-records-exist-how-to-carry/m-p/1414903#M1402</link>
    <description>&lt;P&gt;Hello.&amp;nbsp; I currently have an Attribute Rule which carries over a desired value from a child field to a specified parent field (globalid to GUID, 1:M relationship class).&amp;nbsp; I didn't think about the fact that when multiple child records are associated to a single parent record I need to specify which child record's value will transfer over!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a date field in the child table (DATE_INSPECTION) and would like to be able to bring the most recent/current date value from said field (amongst multiple child records in a 1:M relationship) over to a parent field (DATE_LAST_INSPECTION). It also needs to function if there is only one related child record.&amp;nbsp; I'm not proficient enough in Arcade to figure this out.&amp;nbsp; Any date-related examples I've come across are too complex for me to finagle.&amp;nbsp; If someone (possibly&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/188597"&gt;@MikeMillerGIS&lt;/a&gt;&amp;nbsp;coming in clutch for a second time today??) could help me out, I'd greatly appreciate it!&amp;nbsp;&amp;nbsp;My current code is below.&amp;nbsp; Feel free to tweak it or provide something totally different that might work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Calculation Attribute Rule on Child
// Triggers: Insert, Update
// Field: empty

// do nothing if value did not change
if($originalfeature.CHILD_FIELD == $feature.CHILD_FIELD) { return null }

// get the feature
var TEST = First(FeatureSetByRelationshipName($feature, "OCGIS.DPW_TESTING_REL"))
if(TEST == null) { return null }

// Send a request to update the field in the parent FC
return {
  "edit": [
    {
      "className": "PARENT_NAME",
      "updates": [
        {"globalID": TEST.GlobalID, "attributes": {"PARENT_FIELD": $feature.CHILD_FIELD}}
      ]
    }
  ]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Apr 2024 18:17:17 GMT</pubDate>
    <dc:creator>ChristopherBowering</dc:creator>
    <dc:date>2024-04-24T18:17:17Z</dc:date>
    <item>
      <title>When Multiple Child Records Exist, How to Carry Over Field Value of MOST RECENT Record to Parent Field</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/when-multiple-child-records-exist-how-to-carry/m-p/1414903#M1402</link>
      <description>&lt;P&gt;Hello.&amp;nbsp; I currently have an Attribute Rule which carries over a desired value from a child field to a specified parent field (globalid to GUID, 1:M relationship class).&amp;nbsp; I didn't think about the fact that when multiple child records are associated to a single parent record I need to specify which child record's value will transfer over!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a date field in the child table (DATE_INSPECTION) and would like to be able to bring the most recent/current date value from said field (amongst multiple child records in a 1:M relationship) over to a parent field (DATE_LAST_INSPECTION). It also needs to function if there is only one related child record.&amp;nbsp; I'm not proficient enough in Arcade to figure this out.&amp;nbsp; Any date-related examples I've come across are too complex for me to finagle.&amp;nbsp; If someone (possibly&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/188597"&gt;@MikeMillerGIS&lt;/a&gt;&amp;nbsp;coming in clutch for a second time today??) could help me out, I'd greatly appreciate it!&amp;nbsp;&amp;nbsp;My current code is below.&amp;nbsp; Feel free to tweak it or provide something totally different that might work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Calculation Attribute Rule on Child
// Triggers: Insert, Update
// Field: empty

// do nothing if value did not change
if($originalfeature.CHILD_FIELD == $feature.CHILD_FIELD) { return null }

// get the feature
var TEST = First(FeatureSetByRelationshipName($feature, "OCGIS.DPW_TESTING_REL"))
if(TEST == null) { return null }

// Send a request to update the field in the parent FC
return {
  "edit": [
    {
      "className": "PARENT_NAME",
      "updates": [
        {"globalID": TEST.GlobalID, "attributes": {"PARENT_FIELD": $feature.CHILD_FIELD}}
      ]
    }
  ]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 18:17:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/when-multiple-child-records-exist-how-to-carry/m-p/1414903#M1402</guid>
      <dc:creator>ChristopherBowering</dc:creator>
      <dc:date>2024-04-24T18:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: When Multiple Child Records Exist, How to Carry Over Field Value of MOST RECENT Record to Parent Field</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/when-multiple-child-records-exist-how-to-carry/m-p/1414950#M1403</link>
      <description>&lt;P&gt;This one is a little harder, be easier to write if you can share a sample dataset.&lt;/P&gt;&lt;P&gt;The most performant, would be that we query the table the related record is using the foreign key to get the other records.&amp;nbsp; We then create a sort function by date to get the current date.&amp;nbsp; Then use that key or FSbyRelationship to get the parent record and update it if needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 19:38:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/when-multiple-child-records-exist-how-to-carry/m-p/1414950#M1403</guid>
      <dc:creator>MikeMillerGIS</dc:creator>
      <dc:date>2024-04-24T19:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: When Multiple Child Records Exist, How to Carry Over Field Value of MOST RECENT Record to Parent Field</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/when-multiple-child-records-exist-how-to-carry/m-p/1415126#M1408</link>
      <description>&lt;P&gt;Thanks for responding once again, I appreciate it!&lt;/P&gt;&lt;P&gt;The test datasets I've been using are incredibly simplistic.&amp;nbsp; If you create a point feature class with a GlobalID field and a date field and a table with a GUID field and a date field...using a GlobalID to GUID relationship class, that's the setup I'm using.&amp;nbsp; If there are 5 table records related to a single point, for example, each with a different date, I'd like the most current date to populate the parent date field (or the only existing date if there's only one record).&lt;/P&gt;&lt;P&gt;What you explain makes sense conceptually.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2024 00:29:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/when-multiple-child-records-exist-how-to-carry/m-p/1415126#M1408</guid>
      <dc:creator>ChristopherBowering</dc:creator>
      <dc:date>2024-04-25T00:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: When Multiple Child Records Exist, How to Carry Over Field Value of MOST RECENT Record to Parent Field</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/when-multiple-child-records-exist-how-to-carry/m-p/1415200#M1409</link>
      <description>&lt;P&gt;This should work.&amp;nbsp; If the parent features date is less than the edited child feature, update the parent.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Expects($feature, 'DATEFIELD');
if ($originalfeature.DATEFIELD == $feature.DATEFIELD) {
    return
}

var fs = FeatureSetByRelationshipName($feature, "RELNAME", ['DATEFIELD', 'GLOBALID'], false);

var parent_feat = First(fs);

if (IsEmpty(parent_feat)) {
    return;
}
if (parent_feat.DATEFIELD &amp;gt; $feature.DATEFIELD) {
    return
}


return {
    "edit": [
        {
            "className": "PARENTFCNAME",
            "updates": [{
                "globalID": parent_feat.globalid,
                "attributes": {
                    "Size": $feature.DATEFIELD
                }]
        }
    ]
}&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 25 Apr 2024 09:37:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/when-multiple-child-records-exist-how-to-carry/m-p/1415200#M1409</guid>
      <dc:creator>MikeMillerGIS</dc:creator>
      <dc:date>2024-04-25T09:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: When Multiple Child Records Exist, How to Carry Over Field Value of MOST RECENT Record to Parent Field</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/when-multiple-child-records-exist-how-to-carry/m-p/1415293#M1412</link>
      <description>&lt;P&gt;I will give this a try!&amp;nbsp; I assume the attribution rule is run on the child table with the field set to empty?&amp;nbsp; If it's not too much trouble, could you specify DATEFIELD_Parent or DATEFIELD_Child in your code?&amp;nbsp; Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2024 13:48:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/when-multiple-child-records-exist-how-to-carry/m-p/1415293#M1412</guid>
      <dc:creator>ChristopherBowering</dc:creator>
      <dc:date>2024-04-25T13:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: When Multiple Child Records Exist, How to Carry Over Field Value of MOST RECENT Record to Parent Field</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/when-multiple-child-records-exist-how-to-carry/m-p/1415314#M1413</link>
      <description>&lt;P&gt;Yes this rule would be assigned to the child table.&amp;nbsp; As for code changes, that is an exercise for the reader.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2024 14:31:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/when-multiple-child-records-exist-how-to-carry/m-p/1415314#M1413</guid>
      <dc:creator>MikeMillerGIS</dc:creator>
      <dc:date>2024-04-25T14:31:09Z</dc:date>
    </item>
    <item>
      <title>Re: When Multiple Child Records Exist, How to Carry Over Field Value of MOST RECENT Record to Parent Field</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/when-multiple-child-records-exist-how-to-carry/m-p/1415405#M1415</link>
      <description>&lt;P&gt;I have been playing with this all morning and continue to get script errors on various lines regarding the Child field upon entering a date.&lt;/P&gt;&lt;P&gt;Here is how I've used your script (I've tried both with the attribute rule field empty and on the child field being used):&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Parent Date Field: DATE_1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Child Date Field: DATE_INSPECTION&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;Expects($feature, 'DATE_INSPECTION');
if ($originalfeature.DATE_INSPECTION == $feature.DATE_INSPECTION) {
    return
}

var fs = FeatureSetByRelationshipName($feature, "OCGIS.DPW_TESTING_REL", ['DATE_1', 'GLOBALID'], false);

var parent_feat = First(fs);

if (IsEmpty(parent_feat)) {
    return;
}
if (parent_feat.DATE_INSPECTION &amp;gt; $feature.DATE_1) {
    return
}


return {
    "edit": [
        {
            "className": "OCGIS.DPW_TESTING",
            "updates": [{
                "globalID": parent_feat.globalid,
                "attributes": {
                    "DATE_1": $feature.DATE_INSPECTION
                }]
        }
    ]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first script error message tells me the DATE_INSPECTION field can't be found on line 13.&amp;nbsp; If I swap out the parent for the child field on line 6 the error message then says the DATE_INSPECTION field can't be found on line 8 (which is odd because there isn't even a field present on that line).&lt;/P&gt;&lt;P&gt;I do appreciate your teaching technique mentioned in your last message but I am pretty new at this and am trying my best!&amp;nbsp; Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2024 16:41:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/when-multiple-child-records-exist-how-to-carry/m-p/1415405#M1415</guid>
      <dc:creator>ChristopherBowering</dc:creator>
      <dc:date>2024-04-25T16:41:34Z</dc:date>
    </item>
    <item>
      <title>Re: When Multiple Child Records Exist, How to Carry Over Field Value of MOST RECENT Record to Parent Field</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/when-multiple-child-records-exist-how-to-carry/m-p/1415416#M1416</link>
      <description>&lt;P&gt;You are trying to access a row that not listed in the FeatureSet, make sure you list all the fields you need to use on the parent feature in the 3rd parameters&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var fs = FeatureSetByRelationshipName($feature, "OCGIS.DPW_TESTING_REL", ['DATE_1', 'GLOBALID'], false);&lt;/P&gt;&lt;P&gt;to&lt;/P&gt;&lt;P&gt;var fs = FeatureSetByRelationshipName($feature, "OCGIS.DPW_TESTING_REL", ['DATE_INSPECTION ', 'GLOBALID'], false);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But then you are mixing fields later on in the return statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What date fields are on the parent and what are on the child?&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2024 16:44:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/when-multiple-child-records-exist-how-to-carry/m-p/1415416#M1416</guid>
      <dc:creator>MikeMillerGIS</dc:creator>
      <dc:date>2024-04-25T16:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: When Multiple Child Records Exist, How to Carry Over Field Value of MOST RECENT Record to Parent Field</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/when-multiple-child-records-exist-how-to-carry/m-p/1415418#M1417</link>
      <description>&lt;LI-CODE lang="javascript"&gt;Expects($feature, 'DATE_INSPECTION');
if ($originalfeature.DATE_INSPECTION == $feature.DATE_INSPECTION) {
    return
}

var fs = FeatureSetByRelationshipName($feature, "OCGIS.DPW_TESTING_REL", ['DATE_1', 'GLOBALID'], false);

var parent_feat = First(fs);

if (IsEmpty(parent_feat)) {
    return;
}
if (parent_feat.DATE_1 &amp;gt; $feature.DATE_INSPECTION) {
    return
}


return {
    "edit": [
        {
            "className": "OCGIS.DPW_TESTING",
            "updates": [{
                "globalID": parent_feat.globalid,
                "attributes": {
                    "DATE_1": $feature.DATE_INSPECTION
                }]
        }
    ]
}&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 25 Apr 2024 16:47:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/when-multiple-child-records-exist-how-to-carry/m-p/1415418#M1417</guid>
      <dc:creator>MikeMillerGIS</dc:creator>
      <dc:date>2024-04-25T16:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: When Multiple Child Records Exist, How to Carry Over Field Value of MOST RECENT Record to Parent Field</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/when-multiple-child-records-exist-how-to-carry/m-p/1415435#M1418</link>
      <description>&lt;P&gt;This seems to be working now!&amp;nbsp; I assumed the Parent field would have to be facing the 'less than' side of the operator based on the conceptual description.&amp;nbsp; The remainder of the script I did have correct during one of my attempts but I didn't try switching around the operator on that line.&amp;nbsp; Thank you very much for your help with this scripting.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2024 17:28:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/when-multiple-child-records-exist-how-to-carry/m-p/1415435#M1418</guid>
      <dc:creator>ChristopherBowering</dc:creator>
      <dc:date>2024-04-25T17:28:02Z</dc:date>
    </item>
  </channel>
</rss>

