Using Alternate key to update entity record- Microsoft Dynamics CRM 2015 Update 1

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

  1. Navigate to Settings-> Customizations->Customize the System
  2. Select your entity and expend it, let’s say in our case we want to use Account entity.
  3. Click on Keys->New to setup alternate key for account.
  4. Provide display name for your alternate key, let’s say we want to name it as Integration key
  5. 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.
  6. Save and Close key dialog.

alternamekeys

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

Capture

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:

Capture11

So, we can use alternate keys to update entity records now !!

2 thoughts on “Using Alternate key to update entity record- Microsoft Dynamics CRM 2015 Update 1

  1. Pingback: Using Upsert in Microsoft Dynamics CRM 2015 Update 1 | HIMBAP

  2. Pingback: Using Upsert in Microsoft Dynamics CRM 2015 Update 1 - Microsoft Dynamics CRM Community

Leave a Reply

Your email address will not be published. Required fields are marked *