I got it to run withour errors, but it doesn't actually do what I want it to do.
Input layer = Airfield accident zone
IDPK_Field= AirfieldAccidentIDPK (blank field, text 50 characters)
CALField = AAPZ (user defined, not in table anywhere, set as a parameter)
The final result is giving me AAPZAirfieldAccidentIDPK rather than AAPZ000001
If I run just the first part of the script, it creates the sequential numbers correctly. But once the second part is ran, it gets rid the newly created sequential numbers and gives me the name of the IDPK field
import arcpy
arcpy.env.overwriteOutput = False
Input_Layer = arcpy.GetParameterAsText(0)
IDPK_Field = arcpy.GetParameter(1)
CALField = arcpy.GetParameterAsText(2)
Updated_Input_Table = Input_Layer
arcpy.CalculateField_management(in_table=Input_Layer, field=IDPK_Field, expression="autoIncrement()", expression_type="PYTHON3", code_block="""rec = 0
def autoIncrement():
global rec
pStart = 1
pInterval = 1
if (rec == 0):
rec = pStart
else:
rec = rec + pInterval
return str(rec).zfill(6)""")
arcpy.CalculateField_management(in_table=Input_Layer, field=IDPK_Field, expression='"' + CALField + str(IDPK_Field) + '"', expression_type="PYTHON3", code_block="")