07-18-2023
12:26 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
This should work for you and give you an idea of the syntax:
if(isempty($feature.ApexPoleNumber)){
var poles = FeatureSetByName($datastore,"Pole_NumberingTest",['ApexPoleNumber'],false)
var polenums = []
for (var n in poles){
var nn = Number(n.ApexPoleNumber)
Push(polenums, nn)
}
var maxnum = Max(polenums)
var newnum = maxnum + 1
return newnum
}So, it checks if the current feature ID field is empty, loads the feature class with ApexPoleNumber field, iterates through them all and adds the existing values to a list, finds the max of the list, adds 1 to it, and returns the new number. Some of the lines could be combined, but I think it's easier to read like this.
I should point out that this will fail if there is not at least one feature in the featureclass with a number in it's ApexPoleNumber field.
Also, this link on inserting code will make things a lot nicer and easier to see what is going on in the future.
R_