Select to view content in your preferred language

How to apply query in arcade and caluculate a new ID value?

379
2
07-25-2023 11:05 AM
WilsonLee
Occasional Contributor

Hi,

in the Field Maps form, I'm trying to calculator a new ID value based on a selected grid and the MAX value (+1) in the layer. How can I apply the filter in the expression correctly?

 

Var GRID_ID_SELECT = AA

Var GridFilter = Filter($featureset, ‘GRID_ID = GRID_ID_SELECT')

Var NEW_ID = Max($feature.ID) + 1

return NEW_ID

 

Grid_IDID
AA1
AA2
AA3
BB11
BB12
BB13

 

Thew NEW ID value should be 4.

 

(I'm new to Arcade and trying to figure this out, i have read some samples but didn't achieve my goal)

million thanks!!!

W

 

 

 

 

Tags (3)
0 Kudos
2 Replies
JohannesLindner
MVP Frequent Contributor

You have to get the max of the filtered featureset.

 

var GRID_ID_SELECT = AA
var GridFilter = Filter($featureset, "GRID_ID = @GRID_ID_SELECT")
var NEW_ID = Max(GridFilter, "ID") + 1
return NEW_ID

 


Have a great day!
Johannes
0 Kudos
WilsonLee
Occasional Contributor

Thanks Johannes, for some reason it didn't work

I had simplified the code for this post....the actual codes are like this

For first 3 lines, i am able to get the value from other layer (point in polygon) - ie, GRID_ID

but adding 4,5,6 break the code:

1. var treeGrid = FeatureSetByName($map,"Grid")  

2. var result = Intersects($feature, treeGrid)

3. var GRID_ID = Upper(first(result).MAP_ID)

 

4. var GridFilter = Filter($featureset, "MAP_CODE = @GRID_ID")

5. Var NEWID = Max(GridFilter, "SEQ") + 1

6. return NEWID

 

did i do something wrong? thanks!!!

0 Kudos