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 maintain different keys for your ERP records for the synchronization purpose. But now you do need to 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 useAccount 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 asIntegration key.

  5. Select source field where want to store this key, so let’s say want to utilizeAccount Number field, select Account Number and click on Addbutton.

  6. 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:
  1. //Create Account object with alternate key field and value  
  2.   
  3. Entity account = new Entity(“account”, “accountnumber”, “ERP12345″);   
  4.   
  5. account[“name”] = “Alternate Key Test”;  
  6.   
  7. 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:
  1. Entity accountUpd = new Entity(“account”, “accountnumber”, “ERP12345″);  
  2.   
  3. accountUpd[“name”] = “Alternate Key Demo”;  
  4.   
  5. accountUpd[“websiteurl”] = “www.himbap.com”;  
  6.   
  7. service.Update(accountUpd);  
Now our account record is updated.
 
So, we can use alternate keys to update entity records now !!
 
HIMBAP | Need any help in Microsoft CRM 2015 Development Contact US.
Ebook Download
View all
Learn
View all