GUIDs automatically added to new rows

I’ve gotten pretty proficient at using Coda, but I’m stumped on this one… Hopefully someone is looking for a good challenge!

I want to have a text column in an existing table that automatically gets filled in with a new GUID each time a row is added. Has anyone figured out how to do something like this?

First, I tried putting this as the value for new rows:

=Join("-",
  ToHexadecimal(RoundUp(Random() * 4294967295), 4),
  ToHexadecimal(RoundUp(Random() * 42949), 4),
  ToHexadecimal(RoundUp(Random() * 42949), 4),
  ToHexadecimal(RoundUp(Random() * 42949), 4),
  ToHexadecimal(RoundUp(Random() * 281474976710655), 4)
)

Unfortunately, Coda appears to use the same value for all invocations of Random() within a single calculation. Furthermore, if you add multiple rows at the same time via a copy-paste, each row ends up with the same value.

I figured out a workaround involving buttons, a table of random numbers, and an automation, but does anyone know of a less kludgy way to do this?

Pre-emptive answers to a few questions:

  • Why do I even need a GUID in Coda? For backwards compatibility with an older system from which my team needs to move data into and out of Coda.
  • I’m aware that the above code does not generate a v4-compliant GUID :wink: For my purposes, this is okay.

Hey Matthew, here’s a pseudo-UUID implementation that’s based not on Random but on Coda row UID:

It takes some liberties with reducing entropy (e.g. lowercasing UID characters and leaving out non-base36 characters), but I guess it should be random enough.

1 Like