In Dynamics 365 projects, it is common to have unique ID requirement that should be auto-generated by system. From functional point of view, this ID should be unique and sequential, ID format can be customized, having certain x digits length and with a unique prefix for each entity (e.g. C for Contact). On technical front, it's critical to understand and implement record level locking to avoid generation of duplicate IDs in case multi thread events trigger.
Implementation Options: From implementation point of view, we have below options on the table. Let's evaluate each of these before concluding the best approach.
- Plug-in: Coding custom logic might look an exciting option as you have control of what you need to implement. However, at first it requires development skills and secondly, it might become a maintenance overhead to ensure its functioning after every major D365 release by Microsoft. Moreover, locking implementation can be complex and time consuming to ensure uniqueness of IDs which still may or may not work.
- 3rd Party solution: There are few 3rd party free/paid solutions available in the market to generate unique ID. However, as Microsoft is releasing major upgrades twice a year, it may be a challenge for these providers to provide updated solution to keep the functionality intact and maintenance overhead for system admin to apply these patches. In addition, if 3rd party solution is based on Dynamics 365 plugin it can be failed to generate unique ID as stated above.
- Dynamics 365 Custom Solution: To follow with this approach, we can create a custom entity to store meta data for Unique ID requirement and a workflow to process the actual logic to increment and set the unique ID for each entity (e.g. Contact). This looks simplest and more scalable approach we discussed so far however, the major drawback is as workflows run on application layer, there can be scenarios when multi-thread operations take place and it's quite possible that same ID will be assigned to 2 different records. During testing of this approach, duplicate IDs issue were encountered when multiple users created record at same time. Hence, the basic requirement of ID uniqueness seems to be compromised with this approach
- Power Platform Auto Number Data Type: Recently, Microsoft Power Platform/Apps introduced Auto Number as native data type. System will auto generate the unique IDs in the format choose by user while defining the field. Auto Number field is working on database layer hence uniqueness of IDs is guaranteed. Users can create new Auto Number field or can modify existing one to convert into Auto Number data type. Users have full control to define field length, custom format including prefix/suffix and seed value (starting point).
Limitations: As of now, there are certain limitations or constraints we need to be aware of while using this feature:
- User cannot create this data type from Classic Solution Explorer mode however it can still be used for Dynamics 365 solutions (other than PowerApps) by accessing existing solution (or create new) from Power Portal.
- Seed value can only be set when creating new field and resides in current instance. It means when you import the solution to another instance it will by default start with 1,000 and cannot be modified. Still, there is no impact on generating unique IDs. However, If setting particular seed value is business critical then Auto Number Manager from XRM Toolbox can be used to define this value or custom code can be written to ensure the same.
Note: Do not get confused with PowerApps name in the Portal while using this approach for Dynamics 365 solutions. No additional PowerApps license required as its built-in capability of Dynamics365 and Common Data Service (CDS).
More Details: https://docs.microsoft.com/en-us/powerapps/maker/common-data-service/autonumber-fields
Final Thoughts: As per above discussion, Power Platform Auto Number seems to be the most robust, easiest, scalable and reliable way to implement Unique ID requirement. Hopefully, in next upgrades, above-mentioned limitations will also be addressed by Microsoft.