get field value returns 1

5853
5
03-18-2015 03:39 AM
PaulLohr
Regular Contributor

Anyone have thoughts about why the Get Field Value tool would return "1" instead of the first value of the specified field? In many cases Get Field Value does what it should - it returns the expected value. In a few cases it returns "1" which is not even a choice in the specified field. The field referenced by Get Field Value uses a sting data type.

This is the process string that uses the Get Field Value tool:

Select Layer by Location > Make Feature Layer > Summary Statistics > Add Join > Get Field Value

Calculate Field calls Get Field Value's output using the format "%inline_variable%".

Thanks for any help,

Paul Lohr

5 Replies
DuncanHornby
MVP Notable Contributor

I wonder if it is due to the join? Maybe put in an export to temporary table then do the get field? Just an idea?

0 Kudos
curtvprice
MVP Esteemed Contributor

Paul, without the whole model and test data it's really hard to tell what is happening.

One thing i'm wondering is the data type of the field you're calculating with Calculate Field and the field involved in the join.

One thing that I'm also wondering is whether something may be causing something to be interpreted as boolean. ("1" means True).

0 Kudos
PaulLohr
Regular Contributor

Hello Curtis and Duncan,

There is a long history with ESRI technical support on this issue. The case number is 01619965. Of course most folks won't be able to read the incident history aside from ESRI employees.

curtvprice
MVP Esteemed Contributor

Hey Paul - if you have a bug number those are often accessible to anyone with right-to-call. Incident numbers, we can only see the ones from our own organization.

0 Kudos
curtvprice
MVP Esteemed Contributor

Paul, I have a cute little method I use with the Calculate Value tool that is much more flexible than that tool.

To use it, choose a function below for the code block, and then use an expression like:

get_first(r"%table%")

# Like GetFieldValue
def get_first(tbl, fld):
  return next(arcpy.da.SearchCursor(tbl, fid))[0]
# Get max
def get_max(tbl, fld):
  return sorted(arcpy.da.SearchCursor(tbl, fid))[0][0]
# Get min
def get_min(tbl, fld):
  return sorted(arcpy.da.SearchCursor(tbl, fid), reverse=True)[0][0]

BTW, if you have that bug number, please add it to this thread.