Thanks for the tips. Ok, so I have a couple of updates. The scripts below sort of work. But with my requirement to give new features new unique ID's based off of the max ID for the created user + 1, the scripts skip the last_id by created_user and instead starts at the fallback number for when the created_user is not found.
When does it work? When the field is calculated, only the newly created records are selected. As we know, ArcGIS is going perform the calculation on the selected records only. Most of the time this is a blessing and a free benefit, but in this case, I am not sure how to have the script look in all values attributed to the created user and not just those that are selected in order to find the last ID used by created user and to create the next ID based on that max value. The scripts work when one existing record with an existing ID by created_user exists, then the ID field will first add +1 to the existing ID and calculate the following new records incrementally. See what I mean by sort of works? But not quite, hahaha.
The plan had been to get this calculate to work, then switch out feature names for arcpy.GetParameterAsText() values so that the end user could have a GUI experience and be able to select the feature and column needing new ID's. But alas, I guess I'll just stay with the regular way of doing things, until we can implement the unique id functionality in ArcGIS Pro after some updates on the horizon, but I thought I'd at least share what I have in case it might be a spark for someone.
Version #1
FITID = newid()
def newid():
global last_id
created_user = "BGOVERNANTI"
user_exists = False
last_id = 0
try:
with arcpy.da.SearchCursor("Version\\WaterFitting", ["FITID", "created_user"],
where_clause="{0} = '{1}'".format("created_user", created_user)) as cursor:
for row in cursor:
if row[0] is not None and isinstance(row[0], int) and row[0] > last_id:
last_id = row[0]
user_exists = True
if user_exists:
last_id = last_id + 1
else:
last_id = 10000000 + 1
return last_id
except Exception as e:
print("Error occurred: {}".format(e))
finally:
del cursor
Verson #2
FITID = newid()
def newid():
global last_id
created_user = "BGOVERNANTI"
user_exists = False
last_id = 0
try:
with arcpy.da.SearchCursor("Version\\WaterFitting", ["FITID", "created_user"]) as cursor:
for row in cursor:
if row[1] == created_user:
if row[0] and isinstance(row[0], int) and row[0] > last_id:
last_id = row[0]
user_exists = True
if user_exists:
last_id = last_id + 1
else:
last_id = 10000000 + 1
return last_id
except Exception as e:
print("Error occurred: {}".format(e))
finally:
del cursor