Auto-Incrementing Field for Feature Layer

5651
9
Jump to solution
05-11-2021 01:41 PM
kjohnfs
New Contributor II

TL/DR: Is there a way to auto-increment fields in Field Maps? I'm looking to configure a field with sequential integers for each new point feature (1, 2, 3, 4...)

I work in soils and use Field Maps to collect point features with form data (photo of form attached) in different numbered unit areas. We need to know how many points we have done in each unit, and counting or manually entering the point feature count/number is tedious out in the field. 

Is there a way to auto-increment and display the number point in that unit? For example, if this is the sixth point that a worker has taken in unit 45 is there a way for to autofill "6" in that form?  I saw some posts from 2016 that said Esri was "working on" this functionality.

 

Thank you!

1 Solution

Accepted Solutions
CraigMueller1
New Contributor III

Hey, I've been able to do something similar to your idea using immediate calculation attribute rules and NextSequenceValue.  Having it increment and reset for specific areas is probably outside of the scope of what it can do unless you make a sequence per unit #. 

View solution in original post

9 Replies
CraigMueller1
New Contributor III

Hey, I've been able to do something similar to your idea using immediate calculation attribute rules and NextSequenceValue.  Having it increment and reset for specific areas is probably outside of the scope of what it can do unless you make a sequence per unit #. 

JonathanMcDougall
Occasional Contributor III

@CraigMueller1  I'm a complete newbie to Arcade, I could do with some help on where the "NextSequenceValue('PipeIDSeq')" goes into a form and is this the only code that's needed? I do realise the PipeID will have to reference the correct field.

Many thanks and so sorry for such a basic question.

0 Kudos
CraigMueller1
New Contributor III

Hey Jonathan, sorry for not responding earlier. At the moment running Arcade expressions like NextSequenceValue can't be done in the form, but instead are run at the geodatabase level using calculation attribute rules. Here is an overview page I found on them. In Pro you can set up an attribute rule on a specific field to do a calculation when a specific event occurs. I use immediate calculation rules in a few places to have a field update or populate, and for NextSequenceValue specifically I use it to increment an integer field on insert of a new record. I mention "at the moment" because several blog posts about what's coming in Field Maps have insinuated (at least in my mind) that we may be able to have some attribute rule or similar automated calculations fire at the form level instead of the geodatabase level though I'd imagine in this case it would still only be possible to do at the geodatabase since the sequence itself is set up as a database object using the Create Database Sequence geoprocessing tool. I'm sure all of this explanation is a confusing mess, but I hope the overview steers you in the right direction.

DuncanHornby
MVP Notable Contributor

I ended up at this page as I wanted to achieve the same thing, an incrementing field in FieldMaps.  I had followed the instructions here and I'm using ArcPro 2.8.1. It works fine in ArcPro but does not migrate to FieldMaps when you upload the layers to AGOL. I stumbled around a bit more on the internet and found this recent webinar on Youtube. Jump to about 34:20 and they explain that Attribute Rules are something they are working on. So as of now August 2021 it does not seem to be functionality in FieldMaps but something I hope is released in their next update.

 

AJ_devaccount
Occasional Contributor

Hi @DuncanHornby just checking were you able to set up Attribute Rules in Field Maps yet? I wasn't able to, so was just wondering if the functionality isn't available yet.

0 Kudos
DuncanHornby
MVP Notable Contributor

I've not needed to do such work so have not followed up any development in field maps. So based upon your experience I guess not.

0 Kudos
VincentNoynay
New Contributor

I am trying to create an app for roadway signs collection and have the NextSequenceValue setup on Pro. I got the database sequence setup as well based off some resources online. It works really well on Pro whenever I'd test it to create a new point, the assetID is being created with my desired values and is incrementing properly as well. But when I share it to my org's AGOL and configured it with Field Maps Designer, the assetID just stays at null but the point is successfully created. 

QuantitativeFuturist
Occasional Contributor

What database are you using? If its SQL server there's a specific permission required on the database to use sequences. 

Did you publish the service with attribute rules enabled? 

0 Kudos
KatelynPeterson
New Contributor

I had a similar issue and come up with a solution, though it is not perfect because having multiple editors collecting data in the same land segment while offline would throw off the count. For my survey, I am auto-incrementing the number of trees collected within different project location boundaries. 

Solution:

**For me: Field_1 = Project_Location and Field_2 = Tree_Number

1  var numberlist = FeatureSetByName($map, "Map_Layer", ['Field_1','Field_2'])
2  var location = TextFormatting.SingleQuote + $feature.Field_1 + TextFormatting.SingleQuote
3  var location_sentence = Concatenate(["Field_1 LIKE", location], " " )
4  var current_tree_number = Max(Filter(numberlist, location_sentence), 'Field_2') + 1
5  return current_tree_number
 
To explain what I'm doing here:
 
Line 1: I'm creating a FeatureSet from the layer in my map that contains the fields I need for auto-incrementing. The first field I called was 'Project_Location' and the second field I called was 'Tree_Number'
 
Line 2: Later I will be setting up the Filter() expression to filter Project_Location in the FeatureSet to match the current Project_Location. I knew that I would be using a SQL92 expression in the Filter() function and for that I needed the current Project_Location to be formatted as text with the attribute I am filtering for in single quotations. I decided to make this a variable so that my later lines of code could be cleaner.
 
Line 3:  The SQL92 expression that I am using in the Filter() function filters the Field with a sentence set up as "Field_1 LIKE 'Attribute'". So I am creating a variable that will read "Project_Location LIKE 'location'". This sentence filters the project location to only return the points in the current location. I made this a variable to keep the future code cleaner.
 
Line 4: I am creating my current_tree_number. In this line I am calling Filter() on the FeatureSet I created and filtering it by the current Project_Location. I am then looking for the Max() Tree_Number within that filtered list and then I increase the max by 1 to get my current Tree_Number for the Project_Location. 
 
Line 5: I return the current_tree_number