I have an update cursor that updates rows of a feature class on AGOL. The code below works.
with arcpy.da.UpdateCursor (fc, ['OBJECTID_1', 'Wk4_March29April1_ACTIV','Wk4_HRS', 'Wk5_April5April8_ACTIV','Wk5_HRS'], "Wk4_March29April1_ACTIV LIKE '%Planned%'") as cursor:
for row in cursor:
row[3] = row[1]
row[4] = row[2]
row[1] = None
row[2] = None
cursor.updateRow(row)
I'm now trying to turn this code into a function so I don't have to keep hard coding the values. However, the function I've made isn't working when I call it and pass in the variables I want to use. The code below is the function.
def weekly_update(week_a, hours_a, week_b, hours_b):
with arcpy.da.UpdateCursor (fc, ['OBJECTID_1', 'week_a','hours_a', 'week_b','hours_b'], "week_a LIKE '%Planned%'") as cursor:
for row in cursor:
row[3] = row[1]
row[4] = row[2]
row[1] = None
row[2] = None
cursor.updateRow(row)
#call the function and pass in the variables
weekly_update("Wk25_Oct12Oct15_ACTIV", "Wk25_HRS", "Wk26_Oct19Oct22_ACTIV", "Wk26_HRS")
This is the error I keep getting
RuntimeError: A column was specified that does not exist. [week_a]
Any suggestions would be great. Thanks!