[GIS] Debugging ERROR 000728: Field *fieldname* does not exist within table even though field exists

arcgis-desktoparcpyerror-000728modelbuilder

I do some script for a shapefile's table.

And this script works for 2 fields and do not for other ones, because of:

ERROR 000728: Field FID_158_01 does not exist within table

But this field is fine and EXIST!

enter image description here

Script executed in field calculator.
I take field names from Iterator (Iterate MultiValue).

Expression:

a(!%field_name%!)

Codeblock:

def a(f):
  if f==0:
    z=1
    return z
  elif f==(-1):
    z=0
    return z
  elif f==(1):
    z=1
    return z

Crashlog:

Executing (EXTENT redo math): Model13 H:\TEST\CHECK.shp FID_154_01;FID_153_01;FID_158_01;FID_155_01;FID_153_02
Start Time: Fri Sep 28 14:12:22 2012
Executing (Iterate Multivalue): IterateMultivalue FID_154_01;FID_153_01;FID_158_01;FID_155_01;FID_153_02
Start Time: Fri Sep 28 14:12:23 2012
Succeeded at Fri Sep 28 14:12:23 2012 (Elapsed Time: 0,00 seconds)
Executing (Calculate Field): CalculateField H:\TEST\CHECK.shp FID_154_01 a(!FID_154_01!) PYTHON_9.3 "def a(f):\n  if f==0:\n    z=1\n    return z\n  elif f==(-1):\n    z=0\n    return z\n  elif f==(1):\n    z=1\n    return z"
Start Time: Fri Sep 28 14:12:23 2012
Succeeded at Fri Sep 28 14:12:23 2012 (Elapsed Time: 0,00 seconds)
Executing (Iterate Multivalue): IterateMultivalue FID_154_01;FID_153_01;FID_158_01;FID_155_01;FID_153_02
Start Time: Fri Sep 28 14:12:24 2012
Succeeded at Fri Sep 28 14:12:24 2012 (Elapsed Time: 0,00 seconds)
Executing (Calculate Field): CalculateField H:\TEST\CHECK.shp FID_153_01 a(!FID_153_01!) PYTHON_9.3 "def a(f):\n  if f==0:\n    z=1\n    return z\n  elif f==(-1):\n    z=0\n    return z\n  elif f==(1):\n    z=1\n    return z"
Start Time: Fri Sep 28 14:12:24 2012
Succeeded at Fri Sep 28 14:12:24 2012 (Elapsed Time: 0,00 seconds)
Executing (Iterate Multivalue): IterateMultivalue FID_154_01;FID_153_01;FID_158_01;FID_155_01;FID_153_02
Start Time: Fri Sep 28 14:12:24 2012
Succeeded at Fri Sep 28 14:12:24 2012 (Elapsed Time: 0,00 seconds)
Executing (Calculate Field): CalculateField H:\TEST\CHECK.shp FID_158_01 a(!FID_158_01!) PYTHON_9.3 "def a(f):\n  if f==0:\n    z=1\n    return z\n  elif f==(-1):\n    z=0\n    return z\n  elif f==(1):\n    z=1\n    return z"
Start Time: Fri Sep 28 14:12:25 2012
Failed to execute. Parameters are not valid.
ERROR 000728: Field FID_158_01 does not exist within table
Failed to execute (Calculate Field).
Failed at Fri Sep 28 14:12:25 2012 (Elapsed Time: 0,00 seconds)
Failed to execute (EXTENT redo math).
Failed at Fri Sep 28 14:12:25 2012 (Elapsed Time: 3,00 seconds)

Any ideas?

When i do all the steps in one model it gives me an error.

But when i just make union output file then stop the model and RUN THE SECOND part with field calculations -> error dissapeared and all works fine!!!

Best Answer

Try creating a variable internal to the function. Something like this:

def a(f):
  foo = f
  z=2

  if foo==0:
    z=1
  elif foo == -1:
    z=0
  elif foo==1:
    z=1
  return z

This way you'll also have a clear indication (result is 2) that something went wrong if the field value winds up being something other than 0 or 1. This is one of those things that shouldn't make a difference, but sometimes does because ArcGIS is weird.

It could also be something to do with your selection in the model. If you don't clear your selection, ModelBuilder can do screwy things. So put a "Clear Selection" step in the model as either the first or the last step inside the iteration loop.