ArcGIS FieldMaps Form Calculate Expression to increment IDs in current year only

3597
4
Jump to solution
03-29-2022 04:16 PM
Caitlin_Todd_LCOR
New Contributor III

Hi all, 

I was super excited to see ArcGIS FieldMaps using calculated expressions and conditional visibility expressions! Currently limited to file geodatabases so Immediate (or batch) calculation Attribute Rules can't be utilized yet, so this is an amazing improvement!

I have a short integer field 'CaseNumber' that needs to be incremented by 1 then reset to 1 every year. So it'd go: 

CaseYearCaseNumber
202297
202298
2022

99

20231

 

The expression works when I test it in the browser (See screenshot "casenumseq_browsertesting"), but in FieldMaps it says the field cannot be calculated ("Casenumseq_FieldMapsError"). FieldMaps troubleshooting logs point to line 6 in the expression where I create and filter down my featureset, the error is "Field cannot be found" ("CaseNumseq_FieldMapsLog"). Perhaps I'm creating the featureset the wrong way? 

This is my expression so far;

 

 

//returns the current year
var timestam = Today()
var currentyear = Year(timestam)
 
//increment by 1 from highest number for only features within current year
var numberlist = Filter(FeatureSetById($datastore, /* Sites */ "0",['CaseNumber', 'CaseYear'],false), 'CaseYear=@currentyear')
var topnum = Top(OrderBy(numberlist,'CaseNumber DESC'),1)
var counter = Number(Max(topnum,'CaseNumber'))
var siteid = counter+1

return siteid

 

 

 

Thanks for any advice!

Caitlin

1 Solution

Accepted Solutions
PhilipOhlinger
New Contributor III

Caitlin,

I found your post because I was trying to do the same thing (create an auto-incrementing field). I tried your code, minus the parts about filtering for the current year, and I got the same error within Field Maps.

However, when I switched out the "FeatureSetByID" for "FeatureSetByName" it worked great!

Here's the code I used:

var numberlist = FeatureSetByName($map,"Pole")
var topnum = Top(OrderBy(numberlist,'PoleID DESC'),1)
var counter = Number(Max(topnum,'PoleID'))
var poleid = counter+1
return poleid

View solution in original post

4 Replies
PhilipOhlinger
New Contributor III

Caitlin,

I found your post because I was trying to do the same thing (create an auto-incrementing field). I tried your code, minus the parts about filtering for the current year, and I got the same error within Field Maps.

However, when I switched out the "FeatureSetByID" for "FeatureSetByName" it worked great!

Here's the code I used:

var numberlist = FeatureSetByName($map,"Pole")
var topnum = Top(OrderBy(numberlist,'PoleID DESC'),1)
var counter = Number(Max(topnum,'PoleID'))
var poleid = counter+1
return poleid

Caitlin_Todd_LCOR
New Contributor III

Thanks Philip!!

That did the trick for me too. I did have to separate out my featureset from the Filter though, for some reason it didn't like being in the same line, and would return an error "filter cannot accept parameter". 

But once they were in separate lines, it works great!

Final expression below.

//returns the current year
var timestam = Today()
var currentyear = Year(timestam)
 
//increment by 1 from highest number for only features within current year
var setfeatures = FeatureSetByName($map,"layer_name_here",['CaseNumber','CaseYear'],false)
var numberlist = Filter(setfeatures, 'CaseYear=@currentyear')
var topnum = Top(OrderBy(numberlist,'CaseNumber DESC'),1)
var counter = Number(Max(topnum,'CaseNumber'))
var siteid = counter+1

return siteid

 

LindsayRaabe_FPCWA
Occasional Contributor III

Just putting it out there - this thread has been handy. I wanted to do exactly what you have both done but had no idea how to achieve it. New problem though - when offline, it obviously can't read the whole list unless all features are also offline. Any idea how to delay the calculation to happen at the time of sync to ensure unique values?

Lindsay Raabe
GIS Officer
Forest Products Commission WA
LindsayRaabe_FPCWA
Occasional Contributor III

Got an answer to this on a dedicated post: Solved: Re: Can we set a calculated field to only calculat... - Esri Community

In summary, it needs to be done server side, which means Attribute Rules which at present can only be done in ArcGIS Pro and not ArcOnline. 

Lindsay Raabe
GIS Officer
Forest Products Commission WA