Adding a default GUID to a layer via ArcPy?

232
1
12-01-2020 06:45 PM
AdrianMartinez
New Contributor

I have a valid GUID string that I need to use as the default value for a field on a particular table - this field acts as a foreign key. According to the documentation for AssignDefaultToField_management, the default value argument must match the data type of the field.

I figured that it would be as simple as casting the string into a GUID, like:

uuid.UUID('ea26af74-8d59-41ce-ab24-965e83825b84')

But doing so results in a generic "Object: Error in executing tool" message. I assume that the problem is that the uuid data type in Python isn't actually the same as what's used by ESRI but I can't find any documentation on what that data type is, much less how to cast a string to it. Anyone have any pointers?

I've also tried adding in brackets around the uuid, formatting it like so:

"{{{}}}".format('ea26af74-8d59-41ce-ab24-965e83825b84')

Neither of these worked.

0 Kudos
1 Reply
RandyBurton
MVP Regular Contributor

Perhaps this tech support article will help: How To: Calculate unique identifier values similar to Global IDs 

I don't think a field using a GUID can have a default value set.   An alternative would be to create/use a text field.

0 Kudos