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:
CaseYear | CaseNumber |
2022 | 97 |
2022 | 98 |
2022 | 99 |
2023 | 1 |
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
Solved! Go to Solution.
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,
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
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
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?
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.