I have set one my ArcGIS Pro tool's parameter as optional to auto populate a field ID if the field ID is missing. However, when I tried to populate the field ID, it does not work. How do I set my boolean parameter to true in my script to populated the required ID field? (On a side note, the "with arcpy.da.SearchCursor" block is meant to search in the first row of the column, OBJECTID to determine if it is zero; if the condition is true, then it will calculate the field ID with "!OBJECTID!+1" and if not, it will use "!OBJECTID!", because the ID needs to start with 1. Is there a better way of writing this part of the script? Not my main question, but just curious for other suggestion. Thanks everyone! )
CreatePPTFieldID = arcpy.GetParameterAsText(8)
#Creating the field ID
if (CreatePPTFieldID = "True"):
arcpy.management.AddField(inpourpoint,"ID","Long")
with arcpy.da.SearchCursor(inpourpoint, 'OBJECTID') as cursor:
for row in cursor:
if (row[0]==0):
arcpy.CalculateField_management(inpourpoint,"ID","!OBJECTID!+1")
exit()
else:
arcpy.CalculateField_management(inpourpoint,"ID","!OBJECTID!")
exit()