I have a text field called GIS_ID which I would like to populate with a unique UUID only if it doesn't have a valid UUID already. That is, if the field is NULL, or contains any other value other than a valid UUID, then I want it to populate it with a UUID. If there is already a valid UUID in the field, then I want it to do nothing.

I'm using ArcGIS Desktop 10.4.1 Standard License and I want to populate the field using the field calculator. I'm also aware of GUID Fields in ArcGIS but they aren't suitable for the client's purposes.


I solved this with the following codeblock for the field calculator with the Python parser. I used the uuid module as well as the re module.

The regular expression for UUIDs is:


def CalcUUID(n):
  import uuid
  import re
  if n==None:
    return str(uuid.uuid4()).upper()
  elif rePattern.match(n):
    return n
    return str(uuid.uuid4()).upper()

In the above code, n is the field I want to update which may or may not contain a valid UUID. The expression to run the code is:

CalcGUID( !GIS_ID! )

Where GIS_ID is the field to update.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.