Alternate key is a great addition to useful features in dynamics crm. I have blogged about it here : Work With Alternate Keys
In this blog I just want to quickly show resolution when you create an alternate key and its corresponding job stays in “Pending” Status.
I.e Consider an example of my entity. On my customer entity I have a contact reference field which I would like to be unique. hence I decide to create an alternate key. So I go to Settings > Customizations > Customize the System > Entity > My Enity > Key and create a new one by adding the contact reference field:
- Create new alternate key and add the required field:
- Click Save and Close. you will see job is created and shows you status. However even after waiting for minutes , it shows as “Pending” the expect status should be “Activated”.
- click on the job:
- But there also , you wont see anything 😦
Reason & Resolution
There are two possibilities:
- Since creating an alternate key essentially creates indexing on the table in the database. It will fail if duplicate records are already there.To remove duplicates either use advanced find to manually delete or update records or duplicate detection job to delete the record, see here :Set up duplicate detection rules to keep your data clean
- Other reason I can think of is the job is stuck may be due to some CRM Async Service. Try to delete and recreated the alternate key.
If you are onpremise – you can restart async service and see if that works.
For me 1st one was the issue. I deleted the records with same contact reference number and it worked:
Now I could create the key and it was activated:
I hope this helps!
Concept of Alternate Keys has been introduced with Microsoft Dynamics CRM Version 2016.
All Microsoft Dynamics CRM records have unique identifiers defined as GUIDs. These are the primary key for each entity. However if you have alot integrated systems in your organization – it would be very difficult for other systems to retrieve or update records using the guids as they wont necessarily store CRM’s internal GUIDs. Hence you can create an alternate key which is actually a data in other systems – they can easily update or retrieve data from CRM using this.
Only below field types can be added as an alternate key :
- Decimal Number
- Whole Number
- Single Line of Text
- Date Time [ Only with Dynamics 365 v9 or above]
- Lookup [ Only with Dynamics 365 v9 or above]
- Picklist [ Only with Dynamics 365 v9 or above]
Point to note is that for a single entity, only 5 alternate keys are allowed in CRM.
Apart from Above , Alternate keys will stop creating duplicate records in the system, be it normal creation , excel import , or from external service.Wow how cool is that!
To Create an alternate key , go to customization > Entity> Expand the entity and look for “Alternate Keys” option > click on New and give display name and schema name > select the field for which you want to enable it > click on the right arrow > click on Save.
when you save an alternate key it, you are actually creating an async job which goes through following status :
- In Progress
Once status shows “Active” it means its ready to be used:
you can very well use alternate keys with WebApi , take reference from the below :
Write to me if you have any questions on this topic.
I hope this helps!