{"id":1522,"date":"2015-06-11T04:58:44","date_gmt":"2015-06-11T04:58:44","guid":{"rendered":"https:\/\/mahenderpal.wordpress.com\/?p=1522"},"modified":"2015-12-06T06:07:15","modified_gmt":"2015-12-06T06:07:15","slug":"using-alternate-key-to-update-entity-record-microsoft-dynamics-crm-update-1","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=1522","title":{"rendered":"Using Alternate key to update entity record- Microsoft Dynamics CRM 2015 Update 1"},"content":{"rendered":"<p>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&#8217;t need to do that any more !!\u00a0Microsoft 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\u00a0integration 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<\/p>\n<ol>\n<li>Navigate to <strong>Settings-&gt; Customizations-&gt;Customize the System<\/strong><\/li>\n<li>Select your entity and expend it, let\u2019s say in our case we want to use <strong>Account<\/strong> entity.<\/li>\n<li>Click on <strong>Keys-&gt;New<\/strong> to setup alternate key for account.<\/li>\n<li>Provide display name for your alternate key, let\u2019s say we want to name it as <strong>Integration key<\/strong><\/li>\n<li>Select source field where want to store this key, so let\u2019s say want to utilize <strong>Account Number field<\/strong>, select <strong>Account Number<\/strong> and click on <strong>Add<\/strong> button.<\/li>\n<li><strong>Save and Close<\/strong> key dialog.<\/li>\n<\/ol>\n<p><a href=\"https:\/\/mahenderpal.files.wordpress.com\/2015\/06\/alternamekeys.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-1523 aligncenter\" src=\"https:\/\/mahenderpal.files.wordpress.com\/2015\/06\/alternamekeys.png?w=300\" alt=\"alternamekeys\" width=\"300\" height=\"145\" \/><\/a><\/p>\n<p>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:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/Create Account object with alternate key field and value\r\nEntity account = new Entity(&quot;account&quot;, &quot;accountnumber&quot;, &quot;ERP12345&quot;);\r\naccount[&quot;name&quot;] = &quot;Alternate Key Test&quot;;\r\nservice.Create(account);\r\n<\/pre>\n<p>So our account record is created like below<\/p>\n<p><a href=\"https:\/\/mahenderpal.files.wordpress.com\/2015\/06\/capture.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-1525 aligncenter\" src=\"https:\/\/mahenderpal.files.wordpress.com\/2015\/06\/capture.png?w=300\" alt=\"Capture\" width=\"300\" height=\"202\" \/><\/a><\/p>\n<p>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<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nEntity accountUpd = new Entity(&quot;account&quot;, &quot;accountnumber&quot;, &quot;ERP12345&quot;);\r\n\r\naccountUpd[&quot;name&quot;] = &quot;Alternate Key Demo&quot;;\r\n\r\naccountUpd[&quot;websiteurl&quot;] = &quot;www.himbap.com&quot;;\r\n\r\nservice.Update(accountUpd);\r\n<\/pre>\n<p>Now our account record is updated:<\/p>\n<p><a href=\"https:\/\/mahenderpal.files.wordpress.com\/2015\/06\/capture11.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-1528 aligncenter\" src=\"https:\/\/mahenderpal.files.wordpress.com\/2015\/06\/capture11.png?w=300\" alt=\"Capture11\" width=\"300\" height=\"176\" \/><\/a><\/p>\n<p>So, we can use alternate keys to update entity records now !!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;t need to do that any more !!\u00a0Microsoft Dynamics CRM 2015 Update 1 introduced new feature which allows us to assign alternate unique keys to entity which can help us to&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=1522\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,9],"tags":[127,193,200],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1522"}],"collection":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1522"}],"version-history":[{"count":4,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1522\/revisions"}],"predecessor-version":[{"id":1932,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1522\/revisions\/1932"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}