KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to automatically create unique ID numbers for existing records
PRODUCT: 4D | VERSION: 6.5 | PLATFORM: Mac & Win
Published On: June 1, 2001
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

Create a project method and copy and paste the following code into the method, modifying the table and field name to the appropriate table and field name. After this is done, in the user environment, click "Special" on the menu bar, and select "Execute Method".

C_LONGINT($i) ` myNewUniqueIDField should also be Long Integer
ALL RECORDS([myTable]) ` grab all the records that exist
For ($i;1;Records in selection([myTable])) ` loop through all the records
[myTable]myNewUniqueIDField:=$i ` assign a new unique longint identifier
SAVE RECORD([myTable]) ` save the change
NEXT RECORD([myTable]) ` move to the next record
End for ` lather, rinse, repeat