<?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 sequential count of features by value in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/update-sequential-count-of-features-by-value/m-p/1629467#M1801</link>
    <description>&lt;P&gt;Disregard - meant to reply above.&lt;/P&gt;</description>
    <pubDate>Wed, 02 Jul 2025 16:24:42 GMT</pubDate>
    <dc:creator>MikeA</dc:creator>
    <dc:date>2025-07-02T16:24:42Z</dc:date>
    <item>
      <title>Update sequential count of features by value</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-sequential-count-of-features-by-value/m-p/1629072#M1799</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm trying to create an attribute rule that will create a sequential count of features in one field (NumberID) based on their value in another field (Category). An example is below. Whenever a feature is inserted, updated, or deleted, I'd like the counts in the NumberID field to automatically recalculate based on the occurrences of the values in the Category field. I want the count for each category to start at 1, so a geodatabase sequence doesn't seem to be the way to go. The&amp;nbsp;previous NumberID values don't matter. In other words, it doesn't matter if a feature numbered "1" later becomes "2" as long as every feature in that category is numbered sequentially without skipping any numbers.&lt;/P&gt;&lt;P&gt;&lt;U&gt;Category&lt;/U&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;U&gt;NumberID&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Category1&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;Category1&amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;Category1&amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;Category2&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;Category3&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;Category3&amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;I had some success modifying the solution in the post below to create the counts, but it doesn't recalculate the counts when I delete features. I'd like the NumberID values to recalculate whenever there's an edit so each feature is always numbered 1, 2, 3, etc. by each category.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-pro-questions/sequentially-incrementally-numbering-a-data-point/m-p/1232595#M62347" target="_blank" rel="noopener"&gt;Solved: Re: Sequentially/incrementally numbering a data po... - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Does anyone have any suggestions for how to do this? Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jul 2025 13:40:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-sequential-count-of-features-by-value/m-p/1629072#M1799</guid>
      <dc:creator>MikeA</dc:creator>
      <dc:date>2025-07-02T13:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: Update sequential count of features by value</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-sequential-count-of-features-by-value/m-p/1629388#M1800</link>
      <description>&lt;P&gt;I'm not sure this approach is feasible, as it would likely create an infinite update loop, resulting in the error:&lt;BR /&gt;&lt;STRONG&gt;"The evaluation of attribute rules is cyclic or exceeds maximum cascading level."&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;For example, if your attribute rule is set to trigger on &lt;STRONG&gt;INSERT&lt;/STRONG&gt;, &lt;STRONG&gt;UPDATE&lt;/STRONG&gt;, and &lt;STRONG&gt;DELETE&lt;/STRONG&gt;, any update will recursively trigger the rule again.&lt;/P&gt;&lt;P&gt;Consider this scenario:&lt;BR /&gt;You have two features, Feature_1 and Feature_2, both categorized as "Category_A", with NumberID values of 1 and 2. When you insert a new feature, Feature_3, also with "Category_A", your script filters all features in that category (now totaling 3) and recalculates their NumberID values in sequence.&lt;/P&gt;&lt;P&gt;This update then triggers the rule again for each feature whose NumberID was changed—causing a loop.&lt;BR /&gt;Even if you try to avoid updates by checking whether a feature’s NumberID already matches the expected sequence, eventually a change will occur that re-triggers the rule, continuing the loop.&lt;/P&gt;&lt;P&gt;So unless you implement very strict controls to prevent any form of cyclic triggering, this logic is prone to unintended recursion.&lt;BR /&gt;&lt;BR /&gt;This is an example of code you could start with but it results in the cyclic triggering.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var numberID_field = "NumberID";

var updates = [];
var cnt = 0;

var cat = $feature.Category;
if ($editcontext.editType == "DELETE") {
    cat = $originalFeature.Category;
}

var myFeature = FeatureSetByName($datastore, "{Your feature}", ['*'], false);
var features_with_same_category = Filter(myFeature, "Category = &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/537051"&gt;@Cat&lt;/a&gt;")

for (var f in features_with_same_category) {

    cnt += 1;
    Push(updates, {
        'globalID': f.GlobalID,
        'attributes': Dictionary(numberID_field, cnt)
    });
}

return {
    'edit': [{'className': 'Your feature',  'updates': updates}
        ]
    }&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jul 2025 14:59:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-sequential-count-of-features-by-value/m-p/1629388#M1800</guid>
      <dc:creator>Jake_S</dc:creator>
      <dc:date>2025-07-02T14:59:51Z</dc:date>
    </item>
    <item>
      <title>Re: Update sequential count of features by value</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-sequential-count-of-features-by-value/m-p/1629467#M1801</link>
      <description>&lt;P&gt;Disregard - meant to reply above.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jul 2025 16:24:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-sequential-count-of-features-by-value/m-p/1629467#M1801</guid>
      <dc:creator>MikeA</dc:creator>
      <dc:date>2025-07-02T16:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: Update sequential count of features by value</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-sequential-count-of-features-by-value/m-p/1629480#M1802</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thanks for looking into this and for the info, Jake. I'm new to arcade. I think I follow how a loop would result with the&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;update&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;trigger. I tried the code with just&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;insert&amp;nbsp;&lt;/STRONG&gt;&lt;SPAN&gt;and&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;delete&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;as triggers, and while it calculated new NumberID values when I created new features, the numbers didn't update when I deleted a feature. In other words, I had 3 features in CategoryA, but when I deleted the CategoryA feature with NumberID value 2, I was left with NumberIDs 1 and 3 for the remaining CategoryA features. Any idea why? Thanks again.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jul 2025 16:24:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-sequential-count-of-features-by-value/m-p/1629480#M1802</guid>
      <dc:creator>MikeA</dc:creator>
      <dc:date>2025-07-02T16:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: Update sequential count of features by value</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-sequential-count-of-features-by-value/m-p/1629537#M1803</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/291387"&gt;@MikeA&lt;/a&gt;&amp;nbsp;You can try this one.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// variables //
var numberID_field = "NumberID";
var updates = [];
var cnt = 0;
var cat = $feature.Category;
var originalGlobalID = $originalFeature.GlobalID;

// If the edit type is DELETE, we need to use the original feature's category
// to ensure we are counting features in the same category as the one being deleted.
if ($editcontext.editType == "DELETE") {
    cat = $originalFeature.Category;
}

// Get all features in the same category
var features = FeatureSetByName($datastore, "{Your Feature}", ['GlobalID', 'Category'], false);
var whereClause = "Category = @cat";

// If the edit type is DELETE, we need to exclude the original feature from the count
// to avoid counting it as part of the updates.
if ($editcontext.editType == "DELETE") {
    whereClause += " AND GlobalID &amp;lt;&amp;gt; @originalGlobalID";
}

// Filter features based on the category
var features_with_same_category = Filter(features, whereClause);

for (var f in features_with_same_category) {
    cnt += 1;
    // Create an update object for each feature in the same category
    Push(updates, {
        'globalID': f.GlobalID,
        'attributes': Dictionary(numberID_field, cnt)
    });
}

return {
    'edit': [{ 'className': '{Your Feature}', 'updates': updates }
    ]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;div class="lia-vid-container video-embed-center"&gt;&lt;div id="lia-vid-6375181567112w776h540r974" class="lia-video-brightcove-player-container"&gt;&lt;video-js data-video-id="6375181567112" data-account="6161463677001" data-player="default" data-embed="default" class="vjs-fluid" controls="" data-application-id="" style="width: 100%; height: 100%;"&gt;&lt;/video-js&gt;&lt;/div&gt;&lt;script src="https://players.brightcove.net/6161463677001/default_default/index.min.js"&gt;&lt;/script&gt;&lt;script&gt;(function() {  var wrapper = document.getElementById('lia-vid-6375181567112w776h540r974');  var videoEl = wrapper ? wrapper.querySelector('video-js') : null;  if (videoEl) {     if (window.videojs) {       window.videojs(videoEl).ready(function() {         this.on('loadedmetadata', function() {           this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) {             bar.setAttribute('role', 'presentation');             bar.setAttribute('aria-hidden', 'true');           });         });       });     }  }})();&lt;/script&gt;&lt;a class="video-embed-link" href="https://community.esri.com/t5/video/gallerypage/video-id/6375181567112"&gt;(view in My Videos)&lt;/a&gt;&lt;/div&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jul 2025 17:49:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-sequential-count-of-features-by-value/m-p/1629537#M1803</guid>
      <dc:creator>Jake_S</dc:creator>
      <dc:date>2025-07-02T17:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: Update sequential count of features by value</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-sequential-count-of-features-by-value/m-p/1629640#M1804</link>
      <description>&lt;P&gt;Works great! Thanks again!&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jul 2025 21:42:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-sequential-count-of-features-by-value/m-p/1629640#M1804</guid>
      <dc:creator>MikeA</dc:creator>
      <dc:date>2025-07-02T21:42:45Z</dc:date>
    </item>
  </channel>
</rss>

