Hi, I created a model to run a series of tools, my last step is taking an output table called "screensoutput" with a an empty field within called "inspected" and I want to calculate the "inspected" field. To calculate the "inspected" field, I'm using the screensoutput table (which is a list of assets), and referencing it against "TableR" which contains inspection records for the assets. I want to know what assets haven't been inspected.
Im running the calculate field tool with screensoutput as my input table, selecting the field "inspected" that I want to populate, and the code I'm using is asking to put a 1 where there is a match, and 0 where there is no match when compared to the TableR (list of inspections). The key field in both is screen_id (which is the asset ID)
I keep getting a syntax error. And i think it doesnt like my table name, but I'm sure I've got it right, the table is an output of my model in a previous step, so unless thats becoming an issue?
Any ideas how to fix? this is the final step to get the results and I just cant figure it out. It feels like it should be fairly straight forward.
Solved! Go to Solution.
The expression field expects a simple Python expression. Put your function into the Code Block field.
# Inspected =
check_screen_id(!SCREEN_ID!) # change to your screen id field name, keep the exclamation marks
# Code Block
def check_screen_id(screen_id):
TableR = "..."
with arcpy.da.SearchCursor(TableR, ["screen_id"]) as cursor:
for row in cursor:
if row[0] == screen_id:
return 1
return 0
The expression field expects a simple Python expression. Put your function into the Code Block field.
# Inspected =
check_screen_id(!SCREEN_ID!) # change to your screen id field name, keep the exclamation marks
# Code Block
def check_screen_id(screen_id):
TableR = "..."
with arcpy.da.SearchCursor(TableR, ["screen_id"]) as cursor:
for row in cursor:
if row[0] == screen_id:
return 1
return 0