April 21, 2023

How to use UUID as main id in EspoCRM

EspoCRM offers the option to use UUIDs (Universally Unique Identifiers) as the ID for records. This feature is available since version 7.4 and allows you to generate IDs in a more secure and globally unique way. The available types are “id” (the default 17-character hex) and “uuid4” (UUID version 4). To use the latter, you will need to set the length to 36 or use the uuid data type.

If you plan to switch to the uuid data type for an existing EspoCRM instance, you should be aware that it requires migration work. You will need to ensure that all existing ID values are in a UUID-compatible format, such as by applying an MD5 function. This process applies not only to database ID columns, but also to attachment files and all other references. Therefore, switching to uuid data type may be a non-trivial task.

On the other hand, if you are installing a new instance of EspoCRM, you may consider setting the uuid type before the installation. This way, no migration work will be needed, and you can benefit from the advantages of UUIDs from the start.

Overall, the decision to use UUIDs as ID in EspoCRM depends on your specific needs and situation. If you require a globally unique and secure way to generate IDs, UUIDs may be the way to go. However, if you have an existing instance with data, switching to uuid data type may involve a significant effort.

How to switch to UUID?

Switching to UUID from PHP Unique IDs should be done with caution and only by qualified IT personnel. It’s not recommended to do this on already working instances, but it can be done for new instances. Here are the steps to switch to UUID:

  1. Go to custom/Espo/Custom/Resources/metadata/app – if any of these directories doesn’t exist, create them
  2. Create a file called recordId.json
  3. Paste this code: {"type": "uuid4", "length": 36}
  4. Save the file
  5. Rebuild and clear cache.

Once you’ve completed these steps, all newly generated IDs will be UUIDs. Keep in mind that this change will affect all ID columns, attachment files, and other references, so proceed with caution.

As you can see below, it worked for us:

Official information is available on Github.

Summary

Switching to UUID process for already existing instances can be time-consuming and requires a significant amount of technical knowledge. Therefore, we recommend seeking professional IT services to assist with the migration process. Our team of experts is fully equipped to handle the migration process efficiently and effectively, ensuring that the transition is as smooth as possible for our clients.

Recent posts

Table of Contents

Unlock Your

25% Discount

Sign up and use code BLACKWEEK for an instant discount!
Click here to get more information.

Skip to content