I've created a attribute rule to give every new feature a custom ID, the first part of the ID is 1234AB and the next part needs to be a 4 digit sequential number starting with 0001 (1234AB0001). I have a history feature I need it to reference for duplicates, so if the custom ID field in the history feature already has ID 1234AB0001 then the rule would automatically bump up 1 number and assigned 1234AB0002. Any ideas on how to accomplish this?
You need to query the historic featureclass to obtain the last id, you can do so by referencing the FC using FeatureSetByName
Then you can get the last id from that featureclass using a combination of First(), OrderBy(), and Filter()
Once you obtain the last ID, add +1 and perform your concatenation.
Here is an attribute rule that I use for that:
if(isempty($feature.ID) && $feature.Layer == "ST-DYCL"){
var vals = FeatureSetByName($datastore,"PW_Pro.DBO.Striping",['ID','LENGTH_FT'],false)
var DYCLvals = Filter(vals, "ID LIKE 'DYCL%'")
var numarray = []
for (var n in DYCLvals){
var nn = Number(Replace(n.ID, 'DYCL',''))
Push(numarray, nn)
}
var maxnum = Max(numarray)
var maxtext = Concatenate('DYCL',(Text(maxnum + 1, '00000')))
return maxtext
}
My ID field for this data starts with "DYCL", so this filters for all values that start with that, strips(Replace) the DYCL from it and converts to a number, finds the max value, concatenates that back with the DYCL with incremented number and returns it.
R_
I'll give this a try Rhett! I should have just gave you a call on this. Thanks!