In CRM 2015 Update 1, a new concept for allowing a field to be listed as a primary key outside of the traditional Guids was introduced called Alternate Keys. I had not had a chance to use this feature in-depth so thought this would be a great opportunity to dig into it.
The concept itself is pretty simple – you are integrating Dynamics with another system that has it’s own setup of Primary Keys why not replicate those Ids in Dynamics. If you are deploying a greenfield solution with no integrations to other systems, you’ll probably never use this feature. However, if you have a complex synchronization solution between many line of business solutions where an entity in Dynamics could actually represent 5 disparate resources throughout the rest of your organization, this could be a big win for you.
Creating an Alternate key is pretty easy and can be done from the entity section in Dynamics.
From here you then identify your field as an alternate key in the new “keys” section of your entity.
Which will then show as an alternate key in the Keys section.
Without any other configuration, your new “key” field automatically has Duplicate data detection on it, ensuring that each record has a unique value as a key within it. If a duplicate value is identified, the following warning is presented to the user.
As someone who writes migration/syncing code quite a bit, this is a great way to manage a variety of keys from different environments and ensure data is not getting dirtied. There are some additional SDK functions that enable you to create entities from the alternate key as well.
My only confusion with this feature was that when you mark the field as “an Alternate Key” it doesn’t make it Business Required by default. As a unique key, allowing empty values (even one should not be allowed).