UUID ( Type )
Generate a Universally Unique Identifier (UUID)
Average rating: 3.7 (55 votes) Log in to vote
Tom Robinson - Show more from this author |
Function definition: (Copy & paste into FileMaker's Edit Custom Function window)
This custom function generates a Universally Unique Identifier (UUID) in the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (or the same sans hyphens). e.g. f47ac10b-58cc-4372-a567-0e02b2c3d479.
The advantages of using a UUID over a serial number is there’s no need to worry about the next value of a serial number or a serial number collision, forinstance when importing records. The downside is they’re rarely appropriate to expose to a user.
UUID example: Dick and Harry both create records in their own copies of a database. Each record needs a unique serial number so they can be combined at a later date. After a total of 68,719,476,736 (2^36) records are created the probability of a collision is 0.0000000000000004 (4 × 10^−16)
Comments
David Owen, Bloomfield, CT, USA May 25, 2009 |
||
This looks very valuable. I am wondering about how to parse out the data later if needed. I'd need some help with the calculation. Any CF for that? |
||
The Author, Aotearoa New Zealand Aug 6, 2009 |
||
But how do you want to parse the output? The custom function returns a simple text string which is a standard UUID (either with or without the hyphens). | ||
Alexis Gehrt, Database Designs Nov 30, 2009 |
||
Just one little note: The DecToHex custom function by Jeremiah Small <http://www.briandunning.com/cf/216> is now named: NumToHex Just a simple find/replace.. ;-) |
||
Andreas Thyholdt, dbConsult AS May 11, 2010 |
||
I always get either 0000 or ffff as the last characters when using type 4. Changing the 48-bit number by adding a few numbers on the end does produce random numbers in the last 4 characters, but I am unsure of the consequences, if there are any. Any advice on this? |
||
The Author, Aotearoa New Zealand May 11, 2010 |
||
Thanks Andreas, fixed now. Looks like 10.0v3 fixed the duplication of random numbers but dropped the precision available. | ||
Jens Rasmussen, Danmark Oct 26, 2011 |
||
This entry fails to clearly mention dependence on NumToHex. | ||
Claus Lavendt, Denmark Feb 23, 2012 |
||
Create a simple DB with only one field. Set AutoEnter UUID ( "1h" ) and create a loop script like this: Loop ExitLoop If ( Get ( TotalRecordCount ) > 15000 ) New Record End Loop Search for duplicates and in my tests I found around 748 records, that were not unique. This makes version 1 useless.... Tried the same approach with version 4 and even increased to 250.000 records. No duplicates.... So either there is a bug in the calc or FM has a too low tome resolution for this. |
||
The Author, Aotearoa New Zealand Feb 24, 2012 |
||
Jens: the comments in the code header under ‘Requires’ clearly state the NumToHex dependence. Claus: the comments in the header under ‘Caveats’ clearly state version 1 can return duplicates if called multiple times a second—this is the only situation where it is ‘useless’. |
||
Bachmann Support GmbH, Zurich Mar 2, 2012 |
||
We had the same issue that Claus Lavendt had. With V1 it creates duplicates, not unique UUIDs. V4 works. So dont use V1! |
||
Claus Lavendt, Denmark Mar 14, 2012 |
||
Version 1 would be great if it wasn't for the fact that Filemaker's time resolution only operates in seconds. In e.g. Java, the time resolution operates in miliseconds, which makes version 1 to a great approach, as you also will be able to know which device created the record. So stick to version 4, when using this in Filemaker. Just as a note, one of my colleagues created a test, where he created nearly 4 million records. ALL had unique ID numbers ! This was with version 4. |
||
Claus Lavendt, Denmark Mar 14, 2012 |
||
but, anyway, thank you Tom for creating this very useful CF and for sharing it with us ! | ||
The Author, New Zealand Mar 2, 2015 |
||
Note in FileMaker 12 and later there is now a builtin function get(uuid). | ||
Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.