<?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: Attribute rule isn't triggered when field is updated in a feature in Geodatabase Questions</title>
    <link>https://community.esri.com/t5/geodatabase-questions/attribute-rule-isn-t-triggered-when-field-is/m-p/1270545#M8357</link>
    <description>&lt;P&gt;You created the rule on the basin fc. This rule will only be executed if you change a basin feature. It will do nothing when you change the related table.&lt;/P&gt;&lt;P&gt;To do what you want, you have to create an Attribute Rule on the related table that changes the basin fc. You can do that by returning a dictionary instead of a single value. Documentation of that dictionary can be found here:&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/overview/attribute-rule-dictionary-keywords.htm" target="_blank"&gt;Attribute rule dictionary keywords—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Something like this should work (untested!). Edit lines 7&amp;amp;8 to use the actual field you use for the relationship instead of BasinID!&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Calculation Attribute Rule on the customer table
// field: leave empty
// triggers: insert, update, delete
// exclude from application evaluation

// get all features belonging to the same basin
var basin_id = $feature.BasinID
var query = "BasinID = @basin_id"
if($editcontext.editType == "DELETE") {
    // exclude this feature if we're deleting it
    var oid = $feature.OBJECTID
    query += " AND OBJECTID &amp;lt;&amp;gt; @oid"
}
var wastewater_loads = Filter($featureset, query)

// get the total
var total_gallons = Sum(wastewater_loads, "gallons")

// get the related basin
var basin = First(FeaturesetByRelationshipName("Basins_Pop_Employ_2021_22_TESTENV")
if(basin == null) { return }

// return the dictionary to edit the basin fc
return {
    edit: [{
        className: "Basins_Pop_Employ_2021_22_TESTENV",
        updates: [{
            objectID: basin.OBJECTID,
            attributes: {TGallons: total_gallons}
        }]
    }]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Mar 2023 18:28:52 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2023-03-22T18:28:52Z</dc:date>
    <item>
      <title>Attribute rule isn't triggered when field is updated in a feature</title>
      <link>https://community.esri.com/t5/geodatabase-questions/attribute-rule-isn-t-triggered-when-field-is/m-p/1270013#M8356</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a 1:M relationship class that relates a residences wastewater load (gallons) to the basin they reside in.&amp;nbsp; I created a field (TGallons) in the basin feature (Basins_Pop_Employ_2021_22_TESTENV) with a calculation attribute rule to be populated with the total gallons of all residences in that basin.&amp;nbsp; As an attribute rule, the field (TGallons) will not populate when features are added to the relationship class, are modified/updated, or deleted from it.&amp;nbsp; If I use the same Arcade expression in field calculator, the field will populate with the total number of gallons for the related customers.&amp;nbsp; Why would the attribute rule not trigger?&amp;nbsp; The arcade expression I used is shown below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var related = FeatureSetByRelationshipName($feature, "Basins_Pop_Employ_2021_22_TESTENV_CAF_Addresses_TESTENV")&lt;/P&gt;&lt;P&gt;return sum(related, "gallons")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 19:10:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/attribute-rule-isn-t-triggered-when-field-is/m-p/1270013#M8356</guid>
      <dc:creator>PeterDouglas</dc:creator>
      <dc:date>2023-03-21T19:10:38Z</dc:date>
    </item>
    <item>
      <title>Re: Attribute rule isn't triggered when field is updated in a feature</title>
      <link>https://community.esri.com/t5/geodatabase-questions/attribute-rule-isn-t-triggered-when-field-is/m-p/1270545#M8357</link>
      <description>&lt;P&gt;You created the rule on the basin fc. This rule will only be executed if you change a basin feature. It will do nothing when you change the related table.&lt;/P&gt;&lt;P&gt;To do what you want, you have to create an Attribute Rule on the related table that changes the basin fc. You can do that by returning a dictionary instead of a single value. Documentation of that dictionary can be found here:&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/overview/attribute-rule-dictionary-keywords.htm" target="_blank"&gt;Attribute rule dictionary keywords—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Something like this should work (untested!). Edit lines 7&amp;amp;8 to use the actual field you use for the relationship instead of BasinID!&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Calculation Attribute Rule on the customer table
// field: leave empty
// triggers: insert, update, delete
// exclude from application evaluation

// get all features belonging to the same basin
var basin_id = $feature.BasinID
var query = "BasinID = @basin_id"
if($editcontext.editType == "DELETE") {
    // exclude this feature if we're deleting it
    var oid = $feature.OBJECTID
    query += " AND OBJECTID &amp;lt;&amp;gt; @oid"
}
var wastewater_loads = Filter($featureset, query)

// get the total
var total_gallons = Sum(wastewater_loads, "gallons")

// get the related basin
var basin = First(FeaturesetByRelationshipName("Basins_Pop_Employ_2021_22_TESTENV")
if(basin == null) { return }

// return the dictionary to edit the basin fc
return {
    edit: [{
        className: "Basins_Pop_Employ_2021_22_TESTENV",
        updates: [{
            objectID: basin.OBJECTID,
            attributes: {TGallons: total_gallons}
        }]
    }]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 18:28:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/attribute-rule-isn-t-triggered-when-field-is/m-p/1270545#M8357</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-03-22T18:28:52Z</dc:date>
    </item>
    <item>
      <title>Re: Attribute rule isn't triggered when field is updated in a feature</title>
      <link>https://community.esri.com/t5/geodatabase-questions/attribute-rule-isn-t-triggered-when-field-is/m-p/1272197#M8358</link>
      <description>&lt;P&gt;Thank you very much, this was extremely helpful!&amp;nbsp; I just had to switch from object ID to Global ID, and modify line 20 to read as shown below.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var basin = First(FeaturesetByRelationshipName($feature, "Basins_Pop_Emply_2021_220TESTENV"))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 20:46:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/attribute-rule-isn-t-triggered-when-field-is/m-p/1272197#M8358</guid>
      <dc:creator>PeterDouglas</dc:creator>
      <dc:date>2023-03-27T20:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: Attribute rule isn't triggered when field is updated in a feature</title>
      <link>https://community.esri.com/t5/geodatabase-questions/attribute-rule-isn-t-triggered-when-field-is/m-p/1275397#M8387</link>
      <description>&lt;P&gt;This code worked well and I wanted to use it to update a different related table (2 related tables total) from the same field (gallons), while still updating the original table&lt;SPAN&gt;.&amp;nbsp; What I have now will only update the Basin feature class, but not the Sewer Extension class.&amp;nbsp; Do I need to include both updates in the same dictionary?&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I created/renamed features and relationships from the previous post to make them easier to work with.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// get all features belonging to the same basin and sewer extension
var basin_id = $feature.Basin_ID
var ba_query = "Basin_ID = @basin_id"
var extension = $feature.Extension
var se_query = "Extension = @extension"

if($editcontext.editType == "DELETE") {
    // exclude this feature if we're deleting it
    var ba_gid = $feature.GlobalID
    ba_query += " AND GlobalID &amp;lt;&amp;gt; &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/230169"&gt;@ba&lt;/a&gt;_gid"
    var se_gid = $feature.GlobalID
    se_query += "AND GlobalID &amp;lt;&amp;gt; &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/266579"&gt;@SE&lt;/a&gt;_gid"
}
var wastewater_loads = Filter($featureset, ba_query)
var sewer_loads = Filter($featureset, se_query)

// get the total
var ba_total_gallons = Sum(wastewater_loads, "gallons")
var se_total_gallons = Sum(sewer_loads, "gallons")

// get the related features
var basin = First(FeaturesetByRelationshipName($feature, "Basins_CAF"))
if(basin == null) { return }

// return the dictionary to edit feature classes
return {
    edit: [{
        className: "Basins",
        updates: [{
            GlobalID: basin.GlobalID,
            attributes: {TGallons: ba_total_gallons}
        }]
    }]
}

var sewer = First(FeaturesetByRelationshipName($feature, "Sewer_by_CAF"))
if(sewer == null) { return }

return {
    edit: [{
        classname: "Sewer_Extensions",
        updates: [{
             GlobalID: sewer.GlobalID,
             attributes: {CafCAP: se_total_gallons}
           }]
       }]
 }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 18:10:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/attribute-rule-isn-t-triggered-when-field-is/m-p/1275397#M8387</guid>
      <dc:creator>PeterDouglas</dc:creator>
      <dc:date>2023-04-04T18:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: Attribute rule isn't triggered when field is updated in a feature</title>
      <link>https://community.esri.com/t5/geodatabase-questions/attribute-rule-isn-t-triggered-when-field-is/m-p/1275853#M8390</link>
      <description>&lt;P&gt;Yes, you need to do both edits in the same dictionary.&lt;/P&gt;&lt;P&gt;To do that, it's best to restructure the expression a little:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// get all features belonging to the same basin and sewer extension
var basin_id = $feature.Basin_ID
var ba_query = "Basin_ID = @basin_id"
var extension = $feature.Extension
var se_query = "Extension = @extension"

if($editcontext.editType == "DELETE") {
    // exclude this feature if we're deleting it
    var ba_gid = $feature.GlobalID
    ba_query += " AND GlobalID &amp;lt;&amp;gt; &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/230169"&gt;@ba&lt;/a&gt;_gid"
    var se_gid = $feature.GlobalID
    se_query += " AND GlobalID &amp;lt;&amp;gt; &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/266579"&gt;@SE&lt;/a&gt;_gid"
}
var wastewater_loads = Filter($featureset, ba_query)
var sewer_loads = Filter($featureset, se_query)

// get the total
var ba_total_gallons = Sum(wastewater_loads, "gallons")
var se_total_gallons = Sum(sewer_loads, "gallons")

// construct the edit array
var edit = []
var basin = First(FeaturesetByRelationshipName($feature, "Basins_CAF"))
if(basin != null) {
    var basin_edit = {
        className: "Basins",
        updates: [{
            globalID: basin.GlobalID,
            attributes: {TGallons: ba_total_gallons}
        }]
    }
    Push(edit, basin_edit)
}
var sewer = First(FeaturesetByRelationshipName($feature, "Sewer_by_CAF"))
if(sewer != null) {
    var sewer_edit = {
        classname: "Sewer_Extensions",
        updates: [{
             globalID: sewer.GlobalID,
             attributes: {CafCAP: se_total_gallons}
        }]
    }
    Push(edit, sewer_edit)
}

// return the dictionary to edit feature classes
return {edit: edit}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: You're missing a space before AND in the query in line 12!&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2023 16:19:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/attribute-rule-isn-t-triggered-when-field-is/m-p/1275853#M8390</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-04-05T16:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: Attribute rule isn't triggered when field is updated in a feature</title>
      <link>https://community.esri.com/t5/geodatabase-questions/attribute-rule-isn-t-triggered-when-field-is/m-p/1275982#M8391</link>
      <description>&lt;P&gt;Thank you very much! I had quite a hard time trying to figure that out.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2023 20:53:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/attribute-rule-isn-t-triggered-when-field-is/m-p/1275982#M8391</guid>
      <dc:creator>PeterDouglas</dc:creator>
      <dc:date>2023-04-05T20:53:02Z</dc:date>
    </item>
  </channel>
</rss>

