I'm having a DOH! moment here am can't seem to pull myself out of the nosedive. Converting my scripts using arcpy.CalculateField_management from VB to Python and ran into a small hiccup.
Using VB, this is what I did:
arcpy.CalculateField_management(combinedOutFC + '__ATTACH_vw', 'REL_GLOBALID', '[DBName."Domain\!UserSchema".FC_Publish.GlobalID]')
But in Python, that is not cool so I did this:
arcpy.CalculateField_management(combinedOutFC + '__ATTACH_vw', 'REL_GLOBALID', '!GlobalID!', 'PYTHON_9.3'
Here is the caveat:
Prior to this I performed a join:
arcpy.AddJoin_management(combinedOutFC + "__ATTACH_vw", "REL_GLOBALID", combinedOutFC, "GUIDCopy")
Where I am going wrong with:
arcpy.CalculateField_management(combinedOutFC + '__ATTACH_vw', 'REL_GLOBALID', '!GlobalID!', 'PYTHON_9.3'
Thanks ahead of time for what I know will be "oh yeah" moment of the day for me. Thank you all for your help over the years.
Oh!!! Error is looking like this:
error encountered.ERROR 000539: Invalid field FeatureClass.GlobalID
Failed to execute (CalculateField).
PYTHON ERRORS:
Traceback info:
File "Publish.py", line 182, in <module>
arcpy.CalculateField_management(combinedOutFC + '__ATTACH_vw', 'REL_GLOBALID', '!' + combinedOutFC + '.GlobalID!', 'PYTHON_9.3')Error Info:
ERROR 000539: Invalid field FeatureClass.GlobalID
Failed to execute (CalculateField).
Closing Log File and Exiting Process.
Solved! Go to Solution.
Your error dump messages do not match your code.
I suspect you need a prefix and "." to access the GlobalID field in the related table, especially when there are unusual paths to access the data sources. Although a usually helpful way to find the syntax is to use Describe to use the name property to get the prefix. Note my use of Python .format() -- much easier when the syntax gets weird to keep things straight!
tbl = "{}__ATTACH_vw".format(combinedOutFC)
expr = "!{}.GlobalID!".format(arcpy.Describe(tbl).name)
this doesn't always work, specially when working with SDE joins, raster tables, etc. In these cases sometimes I need to resort to printing a debug message with the field names so I can see what syntax Python is looking for to access the joined field:
print([f.name for f in arcpy.ListFields(tbl)])
Your error dump messages do not match your code.
I suspect you need a prefix and "." to access the GlobalID field in the related table, especially when there are unusual paths to access the data sources. Although a usually helpful way to find the syntax is to use Describe to use the name property to get the prefix. Note my use of Python .format() -- much easier when the syntax gets weird to keep things straight!
tbl = "{}__ATTACH_vw".format(combinedOutFC)
expr = "!{}.GlobalID!".format(arcpy.Describe(tbl).name)
this doesn't always work, specially when working with SDE joins, raster tables, etc. In these cases sometimes I need to resort to printing a debug message with the field names so I can see what syntax Python is looking for to access the joined field:
print([f.name for f in arcpy.ListFields(tbl)])
Oh my, that was an approach I had not considered. Definitely going to give that a shot this morning and will drop you a line with the outcome.
So...after further investigation it turns out:
Thank you for your insight as it was incredibly helpful.