<?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 rules: calculate field based on max and right fonction on insert with Arcade in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/attribute-rules-calculate-field-based-on-max-and/m-p/1207339#M59211</link>
    <description>&lt;P&gt;Thanks you Johannes,&lt;/P&gt;&lt;P&gt;Your last code worked perfectly, the idea to select the max just byorder, I find that very clever.&lt;/P&gt;&lt;P&gt;But the syntax:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;txt[z]= features[z]["code_pat"]&lt;/LI&gt;&lt;LI&gt;txt[z]= features[z].code_pat&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;did not work&lt;/P&gt;&lt;P&gt;any way thanks you very much for your help.&lt;/P&gt;</description>
    <pubDate>Mon, 29 Aug 2022 18:15:02 GMT</pubDate>
    <dc:creator>solidsnake</dc:creator>
    <dc:date>2022-08-29T18:15:02Z</dc:date>
    <item>
      <title>attribute rules: calculate field based on max and right fonction on insert with Arcade</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/attribute-rules-calculate-field-based-on-max-and/m-p/1207047#M59162</link>
      <description>&lt;P&gt;Hello evrybody,&lt;/P&gt;&lt;P&gt;i have somme problème on Arcade statement, i want to insert into a field an expression&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have à table that containe a field "code_pat" as texte where i put à unique calculated id.&lt;/P&gt;&lt;P&gt;The field is composed of two section : text and number like this (PAT0001 -&amp;gt; PAT (text) and 0001 (number)&lt;/P&gt;&lt;P&gt;on insert in want to automaticly add the value with arcade as attrubute rules. so i have to use 3 functions:&lt;/P&gt;&lt;P&gt;1- right, to get the four digit&lt;/P&gt;&lt;P&gt;2- number, to convert each one into number&lt;/P&gt;&lt;P&gt;3- max, to calculate the maximum and add 1&lt;/P&gt;&lt;P&gt;after that i concatenate "PAT" + the max+1 and put il in the field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My arcade :&lt;/P&gt;&lt;P&gt;var features = FeatureSetByName($datastore,"patrimoine",['*']);&lt;/P&gt;&lt;P&gt;var txt = [];&lt;/P&gt;&lt;P&gt;for(var z=0; z&amp;lt;count(features); z++) {&lt;BR /&gt;txt[z]= features.[code_pat].[z]&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;var nb = [];&lt;BR /&gt;nb = number (txt);&lt;/P&gt;&lt;P&gt;var num = max (nb);&lt;/P&gt;&lt;P&gt;return "PAT" + text(num + 1,'0000');&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="solidsnake_0-1661736497277.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/49628i210A7AFB353D582C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="solidsnake_0-1661736497277.png" alt="solidsnake_0-1661736497277.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i got error in this line :&lt;/P&gt;&lt;P&gt;txt[z]= features.[code_pat].[z]&lt;/P&gt;&lt;P&gt;how can i fixe this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks you for your helps&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2022 01:34:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/attribute-rules-calculate-field-based-on-max-and/m-p/1207047#M59162</guid>
      <dc:creator>solidsnake</dc:creator>
      <dc:date>2022-08-29T01:34:42Z</dc:date>
    </item>
    <item>
      <title>Re: attribute rules: calculate field based on max and right fonction on insert with Arcade</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/attribute-rules-calculate-field-based-on-max-and/m-p/1207138#M59179</link>
      <description>&lt;P&gt;You're mixing up a few things...&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN&gt;txt[z]= features.[code_pat].[z]&lt;/SPAN&gt;&lt;UL&gt;&lt;LI&gt;wrong order of code_pat and z. z is the index of the feature in the featureset, code_pat is the attribute of the feature.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;you can either use the dot notation or use the bracket notation to get to the attribute, not both.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;you have to use brackets to get the index&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;if you use brackets, you have to input a string.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;this line should look like this:&lt;/SPAN&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN&gt;txt[z]= features[z]["code_pat"]&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;txt[z]= features[z].code_pat&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;var nb = [];&lt;BR /&gt;nb = number (txt);&lt;/SPAN&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN&gt;Number() only converts a single value, not all elements of an array. you should call Number in the for loop&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;txt looks like this: ["PAT0001", "PAT0002", ...]&amp;nbsp; Number("PAT0001") returns NaN (not a number), because you didn't eliminate the text part before.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are better ways to do what you want:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you are working in an Enterprise Geodatabase, &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/create-database-sequence.htm" target="_blank" rel="noopener"&gt;create a new database sequence&lt;/A&gt; and use it to automatically increment your id field:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var id = NextSequenceValue("NameOfTheDatabaseSequence")
return "PAT" + Text(id, "0000")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you work in a File Geodatabase, you don't need a for loop. You can just order the featureset by your id field (descending), grab the first feature (the one with the max id) and get the number from that:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// get the feature with the highest id
var max_feature = First(OrderBy($featureset, "code_pat DESC"))
// get the number of that id
var max_number = 0
if(max_feature != null) {  // no features in featureset? -&amp;gt; this block is skipped and max_number is 0
    var txt = Replace(max_feature.code_pat, "PAT", "")
    max_number = Number(txt)
}
// calculate and return the new id
return "PAT" + Text(max_number + 1, "0000")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2022 10:02:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/attribute-rules-calculate-field-based-on-max-and/m-p/1207138#M59179</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-08-29T10:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: attribute rules: calculate field based on max and right fonction on insert with Arcade</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/attribute-rules-calculate-field-based-on-max-and/m-p/1207339#M59211</link>
      <description>&lt;P&gt;Thanks you Johannes,&lt;/P&gt;&lt;P&gt;Your last code worked perfectly, the idea to select the max just byorder, I find that very clever.&lt;/P&gt;&lt;P&gt;But the syntax:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;txt[z]= features[z]["code_pat"]&lt;/LI&gt;&lt;LI&gt;txt[z]= features[z].code_pat&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;did not work&lt;/P&gt;&lt;P&gt;any way thanks you very much for your help.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2022 18:15:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/attribute-rules-calculate-field-based-on-max-and/m-p/1207339#M59211</guid>
      <dc:creator>solidsnake</dc:creator>
      <dc:date>2022-08-29T18:15:02Z</dc:date>
    </item>
  </channel>
</rss>

