4

I want to get a list of all GUID fields in a feature class, but it seems that arcpy.ListFields is listing my GUID field as a SmallInteger. What am I doing wrong?

global_id_fieldnames = [f.name for f in arcpy.ListFields(layer) if f.type.lower() == 'guid']

after this list was empty, I called arcpy.AddMessage() for each of the fields:

for f in arcpy.ListFields(layer):
 arcpy.AddMessage('{},{}'.format(f.name, f.type))

enter image description here

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Nov 13, 2013 at 22:51

1 Answer 1

6

I emailed esri support and got this response:

There is a known bug (#NIM055662) for this behavior: [#NIM055662 ListFields and Describe methods are returning SmallInteger FieldType for GUID fields.]

The work-around is to check the field length; if it is longer than a standard "small integer" length, it's a GUID. Field type for a GlobalID field is SmallInteger with length 38 in my test case, much longer than the number of digits in a small integer. A small integer length may vary depending on the platform (although probably not on a Windows platform), but it would not be as large as 38.

following esri's advice, I'm now using:

global_ids_fields = [f.name for f in arcpy.ListFields(layer) if f.type.lower() == 'smallinteger' and f.length == 38]
answered Nov 13, 2013 at 23:22
1
  • 2
    Did ESRI mention if this was version specific? Commented Nov 14, 2013 at 0:57

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.