If you have worked on integrating CRM with another system like ERP, you might have maintained different keys for your ERP records for the synchronization purpose. But now you don’t need to do that any more !! Microsoft Dynamics CRM 2015 Update 1 introduced new feature which allows us to assign alternate unique keys to entity which can help us to update entity record, this is specially useful for integration because you need to keep both keys from both the system to synchronization of the data between two systems. This key can help you to create/update data in CRM without querying entity record primary GUID, which means alternate key will act like a primary key. You can add alternate keys by following below steps
- Navigate to Settings-> Customizations->Customize the System
- Select your entity and expend it, let’s say in our case we want to use Account entity.
- Click on Keys->New to setup alternate key for account.
- Provide display name for your alternate key, let’s say we want to name it as Integration key
- Select source field where want to store this key, so let’s say want to utilize Account Number field, select Account Number and click on Add button.
- Save and Close key dialog.
Now this field will be holding another key field for us that we can use to update this record. So let say first we want to create account record and by setting this key, we can use following code:
//Create Account object with alternate key field and value Entity account = new Entity("account", "accountnumber", "ERP12345"); account["name"] = "Alternate Key Test"; service.Create(account);
So our account record is created like below
Now as this account is created with alternate key, we can simply update this account with the help of alternate key without using accountid field (primary key) like below
Entity accountUpd = new Entity("account", "accountnumber", "ERP12345"); accountUpd["name"] = "Alternate Key Demo"; accountUpd["websiteurl"] = "www.himbap.com"; service.Update(accountUpd);
Now our account record is updated:
So, we can use alternate keys to update entity records now !!