Select to view content in your preferred language

Is sequential numbering based on last known number possible with Arcade in a "new" web map form?

877
2
Jump to solution
04-27-2023 07:48 AM
ThomasColson
MVP Frequent Contributor

I have Solved: Attribute Rule Expressions: calculate max value fr... - Esri Community successfully working in the fgdb environment. What I'm looking to do is replicate in a "new" web map viewer "Form" to autopopulate an unique ID field that IS NOT the objectID nor the GlobalID. Thing is, the data contains many existing records, with this ID ranging from 1-15000, with many values in between missing due to past deletions. What I want is to look at the max value in this field, and have (Arcade?) auto populate the next highest value when the user creates a new point, based on this form. But I don't see how this is possible as AGOL (still!) does not support GDB attribute rules and Create Database Sequence (Data Management)—ArcGIS Pro | Documentation

0 Kudos
1 Solution

Accepted Solutions
RhettZufelt
MVP Notable Contributor

This seems to work in New map viewer and in Field Maps if I set up calculation on the field in the Form.

 

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

 

Depending on how many records, it takes a bit to respond.  Could be a 'faster' way, but I'm not familiar enough with Arcade to figure out how to speed it up.

R_

View solution in original post

2 Replies
RhettZufelt
MVP Notable Contributor

This seems to work in New map viewer and in Field Maps if I set up calculation on the field in the Form.

 

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

 

Depending on how many records, it takes a bit to respond.  Could be a 'faster' way, but I'm not familiar enough with Arcade to figure out how to speed it up.

R_

ThomasColson
MVP Frequent Contributor

And for future folks with this question, this is what worked for my case with actual FC and field name, performance is fine with 2k records. 

var vals = FeatureSetByName($datastore,"COR_HYDROPOWER_PROJECT_POINTS",['HYDRO_PROJECT_ID'],false)
var numarray = []
for (var n in vals){
    var nn = Number(n.HYDRO_PROJECT_ID)
    Push(numarray, nn)
}
var maxnum = Max(numarray)
var newnum = maxnum + 1

return newnum
0 Kudos