<?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: CALCULATION RULE FOR MULTIPLE FIELDS in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-for-multiple-fields/m-p/1307669#M1000</link>
    <description>&lt;P&gt;Thanks a lot Ted!&lt;/P&gt;&lt;P&gt;I realized that and the scripts works perfect, however I misunderstood the requirements of the feature and I need to compare each 'main' field and depending if this is different of 'nilReason' its respective 'secondary' field turns into null.&lt;/P&gt;&lt;P&gt;I've tried this but it seems not to be compatible with dictionary syntax:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var cond = [[$feature.length, $feature.length_nr], [$feature.width, $feature.width_nr], [$feature.radius, $feature.radius_nr]]

for (var i in cond) {
    if (cond[i][0] != 'nilReason') {
        return {
            'result' : {
                'attributes' : {
                    cond[i][1] : null, 
                    }
            }
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think line 8 is the problem, but I'm wondering if is there any way to make the fields contained in "attributes:{}" not static like 'length_nr, width_nr, radius_nr' but dynamic, to validate n data through a loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will be highly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eduardo&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jul 2023 16:39:47 GMT</pubDate>
    <dc:creator>EDUARDOARDILARINCON</dc:creator>
    <dc:date>2023-07-12T16:39:47Z</dc:date>
    <item>
      <title>CALCULATION RULE FOR MULTIPLE FIELDS</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-for-multiple-fields/m-p/1307565#M997</link>
      <description>&lt;P&gt;Hi Everyone! I'm new coding and interacting with arcade, during the last weeks I've tried to implement attibute rules in order to make easier the completion of feature attributes guaranteeing data integrity.&lt;/P&gt;&lt;P&gt;However, once I get into this coding environment and from my poor knowledge about it, I've been trying to improve my code to make it more efficient.&lt;/P&gt;&lt;P&gt;Now, I've discovered that I can use just one script to calculate multiple fields, avoiding creating a single calculation rule for each field (I watched this video &lt;A href="https://www.youtube.com/watch?v=WsO3v5kDLxg)" target="_blank"&gt;https://www.youtube.com/watch?v=WsO3v5kDLxg)&lt;/A&gt;. So with that goal I started to build the code to achieve that multiple calculation in my project, but I failed misserably&amp;nbsp;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":rolling_on_the_floor_laughing:"&gt;🤣&lt;/span&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":rolling_on_the_floor_laughing:"&gt;🤣&lt;/span&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":rolling_on_the_floor_laughing:"&gt;🤣&lt;/span&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Not only I barely understand the sample code, I also created my own FrankenCode and even though it didn't throw any error, it doesn't work properly either.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This is the code I made:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var len = $feature.length
var wid = $feature.width
var rad = $feature.radius

if (len != 'nilReason' || wid != 'nilReason' || rad != 'nilReason') {
    var len_nr = null
    var wid_nr = null
    var rad_nr = null
    return {
        //result is a dictionary or a scalar value
        "result" : {
              "attributes" : {
                       "$feature.length_nr" : len_nr, //update field1 in the $feature 
                       "$feature.width_nr" : wid_nr,  //update field2 in the $feature 
                       "$feature.width_nr" : rad_nr
               }
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;Basically I have 3 main fields (length, width and radius) and 3 secondary fields (length_nr, width_nr and radius_nr), what I want to do is when any of the 3 main fieds is different from 'nilReason', all secondary fields must be calculated as null.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope you can help me again...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eduardo.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 13:30:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-for-multiple-fields/m-p/1307565#M997</guid>
      <dc:creator>EDUARDOARDILARINCON</dc:creator>
      <dc:date>2023-07-12T13:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: CALCULATION RULE FOR MULTIPLE FIELDS</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-for-multiple-fields/m-p/1307594#M998</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/477089"&gt;@EDUARDOARDILARINCON&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Welcome to the amazing world of Arcade and Attribute Rules.&lt;/P&gt;&lt;P&gt;Your code looks good except for two small changes. Remove '$feature.' from your return. The return is looking specifficly for that field name so you returning "$feature.length_nr" is looking for a field called&amp;nbsp;$feature.length_nr not&amp;nbsp;length_nr. Also your return has a duplicate field. Code should look like this...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var len = $feature.length
var wid = $feature.width
var rad = $feature.radius

if (len != 'nilReason' || wid != 'nilReason' || rad != 'nilReason') {
    var len_nr = null
    var wid_nr = null
    var rad_nr = null
    return {
        //result is a dictionary or a scalar value
        "result" : {
              "attributes" : {
                       "length_nr" : len_nr, //update field1 in the $feature 
                       "width_nr" : wid_nr,  //update field2 in the $feature 
                       "radius_nr" : rad_nr
               }
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is some other cleanup you can do but its good from there.&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 12 Jul 2023 14:59:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-for-multiple-fields/m-p/1307594#M998</guid>
      <dc:creator>Jake_S</dc:creator>
      <dc:date>2023-07-12T14:59:33Z</dc:date>
    </item>
    <item>
      <title>Re: CALCULATION RULE FOR MULTIPLE FIELDS</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-for-multiple-fields/m-p/1307602#M999</link>
      <description>&lt;P&gt;There are some good examples with explanations in the doc here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/overview/attribute-rule-dictionary-keywords.htm#ESRI_SECTION1_7FAB1948CDF14FBF9129F8E81463D71E" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/overview/attribute-rule-dictionary-keywords.htm#ESRI_SECTION1_7FAB1948CDF14FBF9129F8E81463D71E&lt;/A&gt;&lt;/P&gt;&lt;P&gt;To answer you question, $feature should not be in your attributes dictionary.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;"result" : {
    "attributes" : {
        "length_nr" : len_nr, //update field1 in the $feature 
        "width_nr" : wid_nr,  //update field2 in the $feature 
        "radius_nr" : rad_nr
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 15:04:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-for-multiple-fields/m-p/1307602#M999</guid>
      <dc:creator>TedHoward2</dc:creator>
      <dc:date>2023-07-12T15:04:15Z</dc:date>
    </item>
    <item>
      <title>Re: CALCULATION RULE FOR MULTIPLE FIELDS</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-for-multiple-fields/m-p/1307669#M1000</link>
      <description>&lt;P&gt;Thanks a lot Ted!&lt;/P&gt;&lt;P&gt;I realized that and the scripts works perfect, however I misunderstood the requirements of the feature and I need to compare each 'main' field and depending if this is different of 'nilReason' its respective 'secondary' field turns into null.&lt;/P&gt;&lt;P&gt;I've tried this but it seems not to be compatible with dictionary syntax:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var cond = [[$feature.length, $feature.length_nr], [$feature.width, $feature.width_nr], [$feature.radius, $feature.radius_nr]]

for (var i in cond) {
    if (cond[i][0] != 'nilReason') {
        return {
            'result' : {
                'attributes' : {
                    cond[i][1] : null, 
                    }
            }
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think line 8 is the problem, but I'm wondering if is there any way to make the fields contained in "attributes:{}" not static like 'length_nr, width_nr, radius_nr' but dynamic, to validate n data through a loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will be highly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eduardo&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 16:39:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-for-multiple-fields/m-p/1307669#M1000</guid>
      <dc:creator>EDUARDOARDILARINCON</dc:creator>
      <dc:date>2023-07-12T16:39:47Z</dc:date>
    </item>
    <item>
      <title>Re: CALCULATION RULE FOR MULTIPLE FIELDS</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-for-multiple-fields/m-p/1307670#M1001</link>
      <description>&lt;P&gt;Thanks a lot JS!&lt;/P&gt;&lt;P&gt;I realized that and the scripts works perfect, however I misunderstood the requirements of the feature and I need to compare each 'main' field and depending if this is different of 'nilReason' its respective 'secondary' field turns into null.&lt;/P&gt;&lt;P&gt;I've tried this but it seems not to be compatible with dictionary syntax:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var cond = [[$feature.length, $feature.length_nr], [$feature.width, $feature.width_nr], [$feature.radius, $feature.radius_nr]]

for (var i in cond) {
    if (cond[i][0] != 'nilReason') {
        return {
            'result' : {
                'attributes' : {
                    cond[i][1] : null, 
                    }
            }
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think line 8 is the problem, but I'm wondering if is there any way to make the fields contained in "attributes:{}" not static like 'length_nr, width_nr, radius_nr' but dynamic, to validate n data through a loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will be highly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eduardo&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 16:40:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-for-multiple-fields/m-p/1307670#M1001</guid>
      <dc:creator>EDUARDOARDILARINCON</dc:creator>
      <dc:date>2023-07-12T16:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: CALCULATION RULE FOR MULTIPLE FIELDS</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-for-multiple-fields/m-p/1307684#M1002</link>
      <description>&lt;P&gt;I think I understand what you're trying to do, but you can only call return once.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var cond = [[$feature.length, "length_nr"], [$feature.width, "width_nr"], [$feature.radius, "radius_nr"]]

attributes = {}
for (var i in cond) {
    if (cond[i][0] != 'nilReason') {
        attributes[cond[i][1]] = null
    }
}
return {'result' : {'attributes' : attributes}}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 17:00:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-for-multiple-fields/m-p/1307684#M1002</guid>
      <dc:creator>TedHoward2</dc:creator>
      <dc:date>2023-07-12T17:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: CALCULATION RULE FOR MULTIPLE FIELDS</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-for-multiple-fields/m-p/1307733#M1003</link>
      <description>&lt;P&gt;This is exactly what I needed, thanks a lot Ted!&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 19:02:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-for-multiple-fields/m-p/1307733#M1003</guid>
      <dc:creator>EDUARDOARDILARINCON</dc:creator>
      <dc:date>2023-07-12T19:02:35Z</dc:date>
    </item>
  </channel>
</rss>

