Hi I'm trying to create a method to write new integer feature ID's based on the highest ID last used by the created user. I'm basing it off of the famous autoIncrement() calculate field python expression and using a search cursor to find the last value used by the creator and incrementing by 1. I am trying to include logic to create an ID even when the user does not exist or when a null value is encountered while looping through. In this particular example, I'm trying to write new FITID's for 4 selected water fitting features. The expression evaluates as valid, but the process completes with a "Warning 002858: WARNING 002858: Certain rows set to NULL due to error while evaluating python expression: File "<string>", line 5, in id". This is similar to the 2016 US Election post where the same error appears and that one had a problem with not having passed arguments into the function properly. Do you have any ideas that I might be able to try?
FITID =
id(!FITID!)
Code Block
last_id = 0
created_user = ""
def id(FITID):
global last_id
rows = arcpy.da.SearchCursor([FITID,created_user],
"{0} = '{1}'".format(created_user, "USER"))
for row in rows:
if row[0] is not None and isinstance(row[0], int) and row[0] > last_id:
last_id = row[0]
user_exists = True
if not user_exists:
last_id = "100000"
pStart = last_id + 1
pInterval = 1 #adjust interval value, if req'd
if (rec == 0):
rec = pStart
else:
rec = rec + pInterval
return rec