<?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: Autonumbering arcade expression works in the Map Viewer but not in Field Maps in ArcGIS Field Maps Questions</title>
    <link>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1312891#M6637</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/138329"&gt;@KerriRasmussen&lt;/a&gt;&amp;nbsp;I just invited arcgisfieldmaps to a group called LSA - Esri Support. I'd appreciate any help you can provide!&lt;/P&gt;</description>
    <pubDate>Thu, 27 Jul 2023 23:04:16 GMT</pubDate>
    <dc:creator>HollyTorpey_LSA</dc:creator>
    <dc:date>2023-07-27T23:04:16Z</dc:date>
    <item>
      <title>Autonumbering arcade expression works in the Map Viewer but not in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1309856#M6552</link>
      <description>&lt;P&gt;I have written this script to autonumber trees our arborists are surveying:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// if this feature already has a Tree Number, return that
if(!IsEmpty($feature.TreeNumber)) { 
  return $feature.TreeNumber 
} else {

  // get the feature with the greatest Tree Number for the current project in the featureset
  var projectNumber = $feature.ProjectNum
  var Tree_features = Filter($featureset, "(TreeNumber IS NOT NULL) AND (ProjectNum = @projectNumber)")
  var max_Tree_feature = First(OrderBy(Tree_features, "TreeNumber DESC"))

  // for an empty featureset, this will be null, so return a 1
  if(max_Tree_feature == null) { return 1 }

  // calculate the max tree number for this project and return the next tree number for the current feature
  var max_TreeNumber = max_Tree_feature.TreeNumber
  var next_TreeNumber = max_TreeNumber + 1
  return next_TreeNumber
}&lt;/LI-CODE&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;BR /&gt;The script works great in the map viewer. If I add a new feature in the particular project I'm working in, it autonumbers the new feature 10 because there are already nine other features. However, if I open the same map in Field Maps and add a new feature, it autonumbers every new feature 1 regardless of the other tree numbers already in the project.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Map Viewer:&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HollyTorpey_LSA_0-1689808836116.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/75820iD6AC6AC0A7B9969F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HollyTorpey_LSA_0-1689808836116.png" alt="HollyTorpey_LSA_0-1689808836116.png" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;HollyTorpey_LSA_0-1689808836116.png&lt;/span&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;Field Maps mobile app:&lt;/DIV&gt;&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HollyTorpey_LSA_1-1689809074136.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/75821i173D2074313170CA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HollyTorpey_LSA_1-1689809074136.png" alt="HollyTorpey_LSA_1-1689809074136.png" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;HollyTorpey_LSA_1-1689809074136.png&lt;/span&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The quick fix is to hard code the project number. We already have to update the Arcade expression that calculates the Project Number field each time we set up a Field Maps map with this layer for a new project, so we could also pop into this script and enter the project number here too. But I don't want to do that because it's an extra step for us to remember to do and because typing in (or pasting in) the project number twice is just an opportunity to introduce error. Plus I just want to know why this works in the Map Viewer but not in the Field Maps mobile app.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks in advance for any help you can provide!&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 19 Jul 2023 23:25:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1309856#M6552</guid>
      <dc:creator>HollyTorpey_LSA</dc:creator>
      <dc:date>2023-07-19T23:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: Autonumbering arcade expression works in the Map Viewer but not in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1310207#M6557</link>
      <description>&lt;P&gt;Hi Holly,&lt;/P&gt;&lt;P&gt;Thank you for sharing this issue. I do have a few questions for you regarding your workflow.&lt;/P&gt;&lt;P&gt;Is this number meant to be a unique identifier?&lt;/P&gt;&lt;P&gt;Will those in the field be using the maps online/offline/both?&lt;/P&gt;&lt;P&gt;What is your ultimate goal for the field you are calculating?&lt;/P&gt;&lt;P&gt;And would you be willing to share the map with us so we can take a look and offer suggestion? If so, you can share it with arcgisfieldmaps.&lt;/P&gt;&lt;P&gt;Lastly, you had asked why your expression worked in the Map Viewer, but it wasn’t working in Field Maps. When you are working with your data in Map Viewer, you have access to the whole table in that feature service, which allows you to see the other feature and their data. That allows your expression to run correctly since you have access to those other records. In Field Maps, when you are working in a form, it takes a much more microscopic view of your data, and you are only working with/looking at one feature at a time. Basically, you can’t run that calculation off other features, because as far as the form is concerned, that is the only feature that exists at the time.&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Kerri&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2023 19:35:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1310207#M6557</guid>
      <dc:creator>KerriRasmussen</dc:creator>
      <dc:date>2023-07-20T19:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: Autonumbering arcade expression works in the Map Viewer but not in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1310255#M6560</link>
      <description>&lt;P&gt;My autonumber script seems to work just fine in Map Viewer, and Field Maps App (on iOS).&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var vals = FeatureSetByName($datastore,"Sign",['TestInt'],false)
var numarray = []
for (var n in vals){
    var nn = Number(n.TestInt)
    Push(numarray, nn)
}
var maxnum = Max(numarray)
var newnum = maxnum + 1

return newnum&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This finds the largest number in the ['TestInt'] field of the feature class named "Sign", adds 1 to it, and populates the TestInt field in the new feature with the incremented value.&lt;/P&gt;&lt;P&gt;Even works offline, but will only find max value of features within the offline area**.&amp;nbsp; So would only use offline if you can download your entire area, AND, there are no other users editing the data.&lt;/P&gt;&lt;P&gt;Have not tested to see if there is a limit to the number of features.&lt;/P&gt;&lt;P&gt;If you have a lot of features in your dataset, it will defiantly increase the time it takes to submit.&lt;/P&gt;&lt;P&gt;Edit:&amp;nbsp; Just tested, and with 2000 records I don't notice any delay.&amp;nbsp; With11,500 records, can take over 10 seconds longer to submit.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2023 00:42:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1310255#M6560</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2023-07-21T00:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: Autonumbering arcade expression works in the Map Viewer but not in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1311707#M6608</link>
      <description>&lt;P&gt;Thanks for the reply and apologies for the delayed response. For some reason I'm not seeing notifications in the Esri Community lately...&lt;/P&gt;&lt;P&gt;Here are my reponses to your questions:&lt;BR /&gt;&lt;BR /&gt;The number is not meant to be a unique identifier, but it is meant to be unique for each individual project number. So for each project number, trees should be numbered starting at 1.&lt;/P&gt;&lt;P&gt;So far it hasn't been used for offline use. I'm assuming it wouldn't work offline... or am I wrong?&lt;/P&gt;&lt;P&gt;The goal is to sequentially number trees within a project area so that arborists don't have to remember/figure out what the next tree number will be. These numbers then are used to label surveyed trees on a map figure that arborists include in their report.&lt;/P&gt;&lt;P&gt;The explanation in your last paragraph is a little confusing to me because when I hardcode the project number, the script works just fine (e.g.,&amp;nbsp;var projectNumber = "12345678"). We were running it like that for months before it occurred to me that I could pull the project number from another field in the form itself and avoid having to update the Arcade for the tree number field. So it was able to query the whole layer to get and sort the range of existing tree numbers for that project number. Am I misunderstanding what you meant?&lt;/P&gt;&lt;P&gt;Thanks again for the response! I'm going to try&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/15530"&gt;@RhettZufelt&lt;/a&gt;'s solution and if that doesn't work out, I'll share the layer with the account you mentioned.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2023 19:27:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1311707#M6608</guid>
      <dc:creator>HollyTorpey_LSA</dc:creator>
      <dc:date>2023-07-25T19:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: Autonumbering arcade expression works in the Map Viewer but not in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1311710#M6609</link>
      <description>&lt;P&gt;Thank you so much!! I will try this out later today and report back.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2023 19:28:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1311710#M6609</guid>
      <dc:creator>HollyTorpey_LSA</dc:creator>
      <dc:date>2023-07-25T19:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: Autonumbering arcade expression works in the Map Viewer but not in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1311806#M6612</link>
      <description>&lt;P&gt;How are you getting the ProjectNum on a 'new' feature?&amp;nbsp; Is this something that you are entering in the form right at first?&amp;nbsp; Do you have separate Field Maps map per project?&lt;/P&gt;&lt;P&gt;Trying to figure out how to filter on a value that doesn't exist on initial feature creation.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2023 22:44:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1311806#M6612</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2023-07-25T22:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: Autonumbering arcade expression works in the Map Viewer but not in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1312745#M6631</link>
      <description>&lt;P&gt;It's a hardcoded field calculation on the Project Number field (e.g. return "12345678"). And yes, we create a new field map for each project, and this data collection template layer gets added to the project. We just have to update the project number field calculation in the smart form (and formerly also the tree numbering script... I updated the script in hopes of only having to add that project number in once place, but then realized it didn't work in the Field Maps mobile app).&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 20:59:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1312745#M6631</guid>
      <dc:creator>HollyTorpey_LSA</dc:creator>
      <dc:date>2023-07-27T20:59:16Z</dc:date>
    </item>
    <item>
      <title>Re: Autonumbering arcade expression works in the Map Viewer but not in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1312852#M6633</link>
      <description>&lt;P&gt;Guess I'm a bit confused.&amp;nbsp; If it is always hardcoded to the same number, why the need for a Filter?&lt;/P&gt;&lt;P&gt;In any case, this works for me to auto populate the next sequential number to the TreeNumber field (Calculated expression on TreeNumber field in form).&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// if this feature already has a Tree Number, return that
if(!IsEmpty($feature.TreeNumber)) { 
  return $feature.TreeNumber 
}
else {
var vals = FeatureSetByName($datastore,"TreeTest",['TreeNumber'],false)
var numarray = []
for (var n in vals){
    var nn = Number(n.TreeNumber)
    Push(numarray, nn)
}
var maxnum = Max(numarray)
var newnum = maxnum + 1

return newnum
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 21:32:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1312852#M6633</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2023-07-27T21:32:17Z</dc:date>
    </item>
    <item>
      <title>Re: Autonumbering arcade expression works in the Map Viewer but not in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1312885#M6636</link>
      <description>&lt;P&gt;It's not always the same project number... I update the project number in the Arcade expression used to calculate that field for each new Field Maps map I set up with this template.&lt;/P&gt;&lt;P&gt;The weird thing is that this works in both the Map Viewer and Field Maps:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// if this feature already has a Tree Number, return that
if(!IsEmpty($feature.TreeNumber)) { 
  return $feature.TreeNumber 

// Otherwise, get the set of trees with the same project number  
} else {

  // Get the Project Number from the ProjectNum field
  var projectNumber = '12345678' //$feature.ProjectNum

  // get the feature with the greatest Tree Number for the current project in the featureset
  
  var Tree_features = Filter($featureset, "(TreeNumber IS NOT NULL) AND (ProjectNum = @projectNumber)")
  var max_Tree_feature = First(OrderBy(Tree_features, "TreeNumber DESC"))

  // for an empty featureset, this will be null, so return a 1
  if(max_Tree_feature == null) { return 1 }

  // calculate the max tree number for this project and return the next tree number for the current feature
  var max_TreeNumber = max_Tree_feature.TreeNumber
  var next_TreeNumber = max_TreeNumber + 1
  return next_TreeNumber
}&lt;/LI-CODE&gt;&lt;P&gt;But this only works in the map viewer (the only thing that changes here is line 9):&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// if this feature already has a Tree Number, return that
if(!IsEmpty($feature.TreeNumber)) { 
  return $feature.TreeNumber 

// Otherwise, get the set of trees with the same project number  
} else {

  // Get the Project Number from the ProjectNum field
  var projectNumber = $feature.ProjectNum

  // get the feature with the greatest Tree Number for the current project in the featureset
  
  var Tree_features = Filter($featureset, "(TreeNumber IS NOT NULL) AND (ProjectNum = @projectNumber)")
  var max_Tree_feature = First(OrderBy(Tree_features, "TreeNumber DESC"))

  // for an empty featureset, this will be null, so return a 1
  if(max_Tree_feature == null) { return 1 }

  // calculate the max tree number for this project and return the next tree number for the current feature
  var max_TreeNumber = max_Tree_feature.TreeNumber
  var next_TreeNumber = max_TreeNumber + 1
  return next_TreeNumber
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;If I add a "return&amp;nbsp;&lt;SPAN&gt;$feature&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;ProjectNum" in line 7, the script populates the TreeNumber with my project number, so I know it's able to pull the calculated project number from the feature.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 22:55:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1312885#M6636</guid>
      <dc:creator>HollyTorpey_LSA</dc:creator>
      <dc:date>2023-07-27T22:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: Autonumbering arcade expression works in the Map Viewer but not in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1312891#M6637</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/138329"&gt;@KerriRasmussen&lt;/a&gt;&amp;nbsp;I just invited arcgisfieldmaps to a group called LSA - Esri Support. I'd appreciate any help you can provide!&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 23:04:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1312891#M6637</guid>
      <dc:creator>HollyTorpey_LSA</dc:creator>
      <dc:date>2023-07-27T23:04:16Z</dc:date>
    </item>
    <item>
      <title>Re: Autonumbering arcade expression works in the Map Viewer but not in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1312906#M6639</link>
      <description>&lt;P&gt;OK, if I'm understanding you correctly, you have a separate Field Maps map for each project, and, when you add a feature, the project number is calculated in the form.&amp;nbsp; So, ALL features added with 'this' map will have the same project number.&amp;nbsp; Let's say it's '1234'.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// if this feature already has a Tree Number, return that
if(!IsEmpty($feature.TreeNumber)) { 
  return $feature.TreeNumber 
}
else {
var trees = FeatureSetByName($datastore,"TreeTest",['TreeNumber'],false)
var Tree_features = Filter(trees, "ProjectNum = '1234'")
var numarray = []
for (var n in Tree_features){
    var nn = Number(n.TreeNumber)
    Push(numarray, nn)
}
var maxnum = Max(numarray)
var newnum = maxnum + 1

return newnum
}&lt;/LI-CODE&gt;&lt;P&gt;If this is the case, the above code is doing exactly has you hoped, and it works in both Map Viewer and Field Maps.&amp;nbsp; You would then just change the '1234' to the project number for each respective map.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I'm still not understanding correctly, I would need to know a little more specifics of how and WHEN the project number gets assigned to help further.&amp;nbsp;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 23:55:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1312906#M6639</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2023-07-27T23:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: Autonumbering arcade expression works in the Map Viewer but not in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1312911#M6640</link>
      <description>&lt;P&gt;Thanks, Rhett. I appreciate your help. Unfortunately, that's what mine already does (probably more clunkily) when I insert the project number into it.&lt;/P&gt;&lt;P&gt;I was trying to avoid having to add the project number to the tree number script because each time we prepare a new Field Maps map (sometimes we do multiple Field Maps per day), we already update the Arcade script for the Project Number field, and I would like to avoid having to also update the script for the Tree Number field.&lt;/P&gt;&lt;P&gt;Since we already entered the project number in the Project Number field, I would like to just pull that value rather than having to type the same thing in two different Arcade scripts for the same form. The issue is not that it's terribly difficult to have to do that, but it's just an opportunity for the person setting up the Field Map to forget to update the tree number field, or to accidentally enter a slightly different project number in each place. Both errors result in the tree numbers not autopopulating correctly. (I think I am making it more confusing here... the last paragraph of my original post probably explains it more succinctly).&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 00:54:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1312911#M6640</guid>
      <dc:creator>HollyTorpey_LSA</dc:creator>
      <dc:date>2023-07-28T00:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: Autonumbering arcade expression works in the Map Viewer but not in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1313107#M6651</link>
      <description>&lt;P&gt;Well, whether you are entering the project number in the field, or if it is being calculated, you need some way for that to get populated.&amp;nbsp; If it is populated, then this script will find the highest tree number for that project and populate the tree number field.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// if this feature already has a Tree Number, return that
if(!IsEmpty($feature.TreeNumber)) { 
  return $feature.TreeNumber 
}
else {
var trees = FeatureSetByName($datastore,"TreeTest",['TreeNumber'],false)
var projectNumber = $feature.ProjectNum
var Tree_features = Filter(trees, "ProjectNum = @projectNumber")
var numarray = []
for (var n in Tree_features){
    var nn = Number(n.TreeNumber)
    Push(numarray, nn)
}
var maxnum = Max(numarray)
var newnum = maxnum + 1

return newnum
}&lt;/LI-CODE&gt;&lt;P&gt;This works if the project number is typed in manually, calculated by the form, picked from a dropdown list, or populated with a template, etc.&amp;nbsp; So, depending on how may projects you have, there may be a less cumbersome way to deal with it than editing the arcade all the time.&lt;/P&gt;&lt;P&gt;Could make a separate map for each project, create a domain so there is a dropdown list to pick the project number in the form, (can always have them type it in), or, could create templates so there is a button for each project that has projectNum default value.&amp;nbsp; That way, when you add a new feature with it, the correct project number is entered, then it has enough info to find/update the tree number.&lt;/P&gt;&lt;P&gt;By what ever method used to assign the project number, this should work fine 'once' the project number is in the field so the form has access to it.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 15:06:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1313107#M6651</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2023-07-28T15:06:27Z</dc:date>
    </item>
    <item>
      <title>Re: Autonumbering arcade expression works in the Map Viewer but not in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1313150#M6653</link>
      <description>&lt;P&gt;This does work in both the map viewer and in Field Maps, so thank you very much!&lt;/P&gt;&lt;P&gt;But I still don't understand why this one works in Field Maps and mine doesn't... Is the key difference that you are using FeatureSetByName to get the featureset to filter rather than just filtering $featureset directly?&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 16:21:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1313150#M6653</guid>
      <dc:creator>HollyTorpey_LSA</dc:creator>
      <dc:date>2023-07-28T16:21:12Z</dc:date>
    </item>
    <item>
      <title>Re: Autonumbering arcade expression works in the Map Viewer but not in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1313252#M6657</link>
      <description>&lt;P&gt;When I saw the reference saying it wasn't possible because the form only had access to the current feature, I didn't really spend time picking apart your code, but offered an example that I already had that I knew was working.&lt;/P&gt;&lt;P&gt;However, if I replace my code with $featureset instead, it still works fine in both.&lt;/P&gt;&lt;P&gt;Turns out, that for some reason, you line 12 is evaluating to Null in Field Maps, so returns the value of 1.&amp;nbsp; Not sure why it works in Map Viewer, but, as you have seen, it does.&lt;/P&gt;&lt;P&gt;So, I added a console statement to return the max_Tree_feature and saw that it is returning a dictionary string:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RhettZufelt_0-1690575287173.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/76708i891D9FC96F618485/image-size/large?v=v2&amp;amp;px=999" role="button" title="RhettZufelt_0-1690575287173.png" alt="RhettZufelt_0-1690575287173.png" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;RhettZufelt_0-1690575287173.png&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So I tested by just extracting the TreeNumber value from the string to test for null (line 12) and it worked.&lt;/P&gt;&lt;P&gt;So, after all that, if I would have just said to replace line 12 with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;  if(max_Tree_feature.TreeNumber == null) { return 1 }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then your original code works as expected in both map viewer and Field Maps.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 20:22:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1313252#M6657</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2023-07-28T20:22:55Z</dc:date>
    </item>
    <item>
      <title>Re: Autonumbering arcade expression works in the Map Viewer but not in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1313307#M6658</link>
      <description>&lt;P&gt;Good grief! Thank you for figuring that out. I obviously need to use the console.&lt;/P&gt;&lt;P&gt;I really appreciate all the time you put into answering this question! Thank you so much.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 23:23:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/autonumbering-arcade-expression-works-in-the-map/m-p/1313307#M6658</guid>
      <dc:creator>HollyTorpey_LSA</dc:creator>
      <dc:date>2023-07-28T23:23:34Z</dc:date>
    </item>
  </channel>
</rss>

