<?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: Update multiple fields using key field in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/update-multiple-fields-using-key-field/m-p/1321521#M1059</link>
    <description>&lt;P&gt;The Attribute Rule needs to know which features it has to update. That is why you have to supply the GlobalID or OBJECTID of the features in the update array. Take a look at the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/overview/attribute-rule-dictionary-keywords.htm" target="_blank" rel="noopener"&gt;documentation of the return dictionary&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;Some other problems:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;You're using an outdated method of appending elements to an array (counter++). If you're using ArcGIS Pro 2.7+ / Enterprise 10.9+, you can use &lt;A href="https://developers.arcgis.com/arcade/function-reference/array_functions/#push" target="_blank" rel="noopener"&gt;Push()&lt;/A&gt;.&lt;/LI&gt;&lt;LI&gt;When you don't find related features, you return a string, but the rule has no assigned field. I don't actually know if that will give an error, but it's useless at least, nobody will see that message.&lt;/LI&gt;&lt;LI&gt;Instead of using Count() (slower) and the error message, just do the for loop and return the result. If the update array is empty, nothing will happen.&lt;/LI&gt;&lt;LI&gt;You're using the values that are already in the asset info table, so nothing will change. You have to use the attributes of $feature&lt;/LI&gt;&lt;LI&gt;You're using assTabList for updates and adds. This will update the features in tbl_asset_info and add new ones, giving you duplicates. What you want to do is this:&lt;UL&gt;&lt;LI&gt;If you're inserting a new features, use adds&lt;/LI&gt;&lt;LI&gt;If you're updating a feature, use updates&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="javascript"&gt;// Rule for asset_july_2023
// triggers: insert, update
// field: no select

// arrays that store adds and updates to the asset info table
var assAdds= []
var assUpdates = []

// attributes of the $feature
var featureAttributes = {          
  'ASSET_ID': $feature.ASSET_ID,                
  'TYPE': $feature.TYPE,
  'VALUE': $feature.VALUE
  }

// if this is an insert, add a new asset info feature
if($editcontext.editType == "INSERT") {
  var newAss = {
    'attributes': featureAttributes
    }
   Push(assAdds, newAss)
}

// if this is an update, edit all related asset info features
if($editcontext.editType == "INSERT") {
  // value of shared field
  var key = $feature["Asset_NAME"]
  // search for related features in tbl_asset_info feature class
  var assInfFS = FeatureSetByName($datastore, "tbl_asset_info", ["*"], false)
  var assInfFilter = Filter(assInfFS, "Asset_NAME = &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/301813"&gt;@Key&lt;/a&gt;")
  for(var asst in assInFilter) {
    var update = {
      "globalID": asst.GlobalID,
      'attributes': featureAttributes
      }
    Push(assUpdates, update)
  }
}

return {
  'edit': [{
    'className': 'asset_july_2023',
    'adds': assAdds,
    'updates': assUpdates
    }]
  }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 23 Aug 2023 08:17:13 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2023-08-23T08:17:13Z</dc:date>
    <item>
      <title>Update multiple fields using key field</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-multiple-fields-using-key-field/m-p/1321489#M1058</link>
      <description>&lt;P&gt;Hello, I am just stack with preparing Arcade expression for immediate calculation. By the immediate calculation, I would like to update three fields based on a table's attributes via a key field when new creation or update of a existing feature.&lt;/P&gt;&lt;P&gt;I have prepared a code as per below but I will get an error as per below when I create a new feature. If anyone know a solution for this, match appreciated.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Rule for asset_july_2023
// triggers: insert, update
// field: no select

// value of shared field
var key = $feature["Asset_NAME"]

// search for related features in tbl_asset_info feature class
var assInfFS = FeatureSetByName($datastore, "tbl_asset_info", ["*"], false)
var assInfFilter = Filter(assInfFS, "Asset_NAME = &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/301813"&gt;@Key&lt;/a&gt;")

var assTabList = []
var counter = 0
var numAsset = Count(assInfFilter)
if (numAsset &amp;gt; 0) {
    for (var asst in assInfFilter) {
        assTabList[counter] = {
            'attributes': {          
                'ASSET_ID': asst.ASSET_ID,                
                'TYPE': asst.TYPE,
                'VALUE': asst.VALUE
            }
        }
        counter++
    }
    return {
        'edit': [{
            'className': 'asset_july_2023',
            'adds':assTabList,
            'updates': assTabList
        }]
    }
} else {
    return 'No common asset in the asset info table.'
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="A88_0-1692761166630.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/78884iFBC54C0BD801797C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="A88_0-1692761166630.png" alt="A88_0-1692761166630.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2023 03:33:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-multiple-fields-using-key-field/m-p/1321489#M1058</guid>
      <dc:creator>Aнастасия88</dc:creator>
      <dc:date>2023-08-23T03:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: Update multiple fields using key field</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-multiple-fields-using-key-field/m-p/1321521#M1059</link>
      <description>&lt;P&gt;The Attribute Rule needs to know which features it has to update. That is why you have to supply the GlobalID or OBJECTID of the features in the update array. Take a look at the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/overview/attribute-rule-dictionary-keywords.htm" target="_blank" rel="noopener"&gt;documentation of the return dictionary&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;Some other problems:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;You're using an outdated method of appending elements to an array (counter++). If you're using ArcGIS Pro 2.7+ / Enterprise 10.9+, you can use &lt;A href="https://developers.arcgis.com/arcade/function-reference/array_functions/#push" target="_blank" rel="noopener"&gt;Push()&lt;/A&gt;.&lt;/LI&gt;&lt;LI&gt;When you don't find related features, you return a string, but the rule has no assigned field. I don't actually know if that will give an error, but it's useless at least, nobody will see that message.&lt;/LI&gt;&lt;LI&gt;Instead of using Count() (slower) and the error message, just do the for loop and return the result. If the update array is empty, nothing will happen.&lt;/LI&gt;&lt;LI&gt;You're using the values that are already in the asset info table, so nothing will change. You have to use the attributes of $feature&lt;/LI&gt;&lt;LI&gt;You're using assTabList for updates and adds. This will update the features in tbl_asset_info and add new ones, giving you duplicates. What you want to do is this:&lt;UL&gt;&lt;LI&gt;If you're inserting a new features, use adds&lt;/LI&gt;&lt;LI&gt;If you're updating a feature, use updates&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="javascript"&gt;// Rule for asset_july_2023
// triggers: insert, update
// field: no select

// arrays that store adds and updates to the asset info table
var assAdds= []
var assUpdates = []

// attributes of the $feature
var featureAttributes = {          
  'ASSET_ID': $feature.ASSET_ID,                
  'TYPE': $feature.TYPE,
  'VALUE': $feature.VALUE
  }

// if this is an insert, add a new asset info feature
if($editcontext.editType == "INSERT") {
  var newAss = {
    'attributes': featureAttributes
    }
   Push(assAdds, newAss)
}

// if this is an update, edit all related asset info features
if($editcontext.editType == "INSERT") {
  // value of shared field
  var key = $feature["Asset_NAME"]
  // search for related features in tbl_asset_info feature class
  var assInfFS = FeatureSetByName($datastore, "tbl_asset_info", ["*"], false)
  var assInfFilter = Filter(assInfFS, "Asset_NAME = &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/301813"&gt;@Key&lt;/a&gt;")
  for(var asst in assInFilter) {
    var update = {
      "globalID": asst.GlobalID,
      'attributes': featureAttributes
      }
    Push(assUpdates, update)
  }
}

return {
  'edit': [{
    'className': 'asset_july_2023',
    'adds': assAdds,
    'updates': assUpdates
    }]
  }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2023 08:17:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-multiple-fields-using-key-field/m-p/1321521#M1059</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-08-23T08:17:13Z</dc:date>
    </item>
    <item>
      <title>Re: Update multiple fields using key field</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-multiple-fields-using-key-field/m-p/1321956#M1062</link>
      <description>&lt;P&gt;Hi Johannes,&lt;/P&gt;&lt;P&gt;What I would like to do actually is extracting attributes from a table to update attributes of a point feature class (asset_july_2023). So I have modified the given code as per below screenshot but still not work. Error says Unexpected null for the line 19.&lt;/P&gt;&lt;LI-CODE lang="java"&gt;// Rule for asset_july_2023 (poihnt)
// triggers: insert, update
// field: no select

// arrays that store adds and updates to the asset info table
var assAdds= []
var assUpdates = []

  // value of shared field
  var key = $feature["Asset_NAME"]
  // search for related features in tbl_asset_info feature class
  var assInfFS = FeatureSetByName($datastore, "tbl_asset_info", ["*"], false)
  var assInfFilter = First(Filter(assInfFS, "Asset_NAME = &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/301813"&gt;@Key&lt;/a&gt;"))

// if this is an insert, add a new asset_july_2023 point feature
if($editcontext.editType == "INSERT") {
  var newAss = {
    'attributes': {          
        'ASSET_ID': assInfFilter.ASSET_ID,                
        'TYPE': assInfFilter.TYPE,
        'VALUE': assInfFilter.VALUE
        }
    }
   Push(assAdds, newAss)
}

// if this is an update, edit all related asset_july_2023 point feature
if($editcontext.editType == "UPDATE") {
    var update = {
        "globalID": assInfFilter.GlobalID,
        'attributes': {          
            'ASSET_ID': assInfFilter.ASSET_ID,                
            'TYPE': assInfFilter.TYPE,
            'VALUE': assInfFilter.VALUE
            }
        }
    Push(assUpdates, update)
}

return {
  'edit': [{
    'className': 'asset_july_2023',
    'adds': assAdds,
    'updates': assUpdates
    }]
  }&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2023 23:12:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-multiple-fields-using-key-field/m-p/1321956#M1062</guid>
      <dc:creator>Aнастасия88</dc:creator>
      <dc:date>2023-08-23T23:12:49Z</dc:date>
    </item>
    <item>
      <title>Re: Update multiple fields using key field</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-multiple-fields-using-key-field/m-p/1321964#M1063</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;I would like to extract attribute from a table to update attributes of a point feature class&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;Ah. Well, that is not what your original attribute rule does (and so it's also not what my rule does). These rules will do it the other way around: They will update/add a row in the table when you update/add a point in the feature class.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;No worries, what you want is actually easier:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Calculation Attribute Rule on asset_july_2023
// trigers: Insert, Update
// field: empty

// get the first related row from tbl_asset_info
var key = $feature.Asset_NAME
var asset_infos = FeatureSetByName($datastore, "tbl_asset_info", ["*"], false)
var asset_info = First(Filter(asset_infos, "Asset_NAME = &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/301813"&gt;@Key&lt;/a&gt;"))

// abort if no related row was found
if(asset_info == null) { return }

// return the related row's attributes
return {
    result: {
        attributes: {
            ASSET_ID: asset_info.ASSET_ID,
            TYPE: asset_info.TYPE,
            VALUE: asset_info.VALUE,
            }
        }
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The null check in line 11 will solve your error message.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2023 23:25:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-multiple-fields-using-key-field/m-p/1321964#M1063</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-08-23T23:25:32Z</dc:date>
    </item>
    <item>
      <title>Re: Update multiple fields using key field</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-multiple-fields-using-key-field/m-p/1321972#M1064</link>
      <description>&lt;P&gt;Thank you Johannes,&lt;/P&gt;&lt;P&gt;It works fine. Also, thanks for the other option that works the other way around. I am going to adjust some parameters to agree with the rules and play around that as well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Aug 2023 00:12:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-multiple-fields-using-key-field/m-p/1321972#M1064</guid>
      <dc:creator>Aнастасия88</dc:creator>
      <dc:date>2023-08-24T00:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: Update multiple fields using key field</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-multiple-fields-using-key-field/m-p/1406067#M1383</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/257092"&gt;@Aнастасия88&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;I am trying to do something similar to what both you and Johannes have laid out.&amp;nbsp; However, I am using a GlobalID (parent feature class) to GUID (table) relationship.&amp;nbsp; I am struggling with how to incorporate that into your examples since I don't have a common 'key' field that is shared between the feature class and table.&amp;nbsp; Would you be able to advise how to do this?&amp;nbsp; Thanks!&lt;/P&gt;&lt;DIV class=""&gt;&lt;A href="https://community.esri.com/t5/attribute-rules-questions/update-multiple-fields-using-key-field/td-p/1321489#" target="_blank" rel="noopener"&gt;PREVIEW&lt;/A&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 04 Apr 2024 21:11:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-multiple-fields-using-key-field/m-p/1406067#M1383</guid>
      <dc:creator>ChristopherBowering</dc:creator>
      <dc:date>2024-04-04T21:11:37Z</dc:date>
    </item>
  </channel>
</rss>

