{"id":2930,"date":"2016-05-27T16:59:45","date_gmt":"2016-05-27T11:29:45","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=2930"},"modified":"2023-02-28T14:12:53","modified_gmt":"2023-02-28T08:42:53","slug":"web-api-enhancements-in-dynamics-crm-update-1","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2016\/05\/web-api-enhancements-in-dynamics-crm-update-1\/","title":{"rendered":"Web API Enhancements in Dynamics CRM Update 1"},"content":{"rendered":"<p><strong>Introduction:<\/strong><\/p>\n<p>Microsoft Dynamics CRM 2016 introduced a new concept called Web API which can be used across wide variety of devices, programming languages and platforms. With the release of Update 1 for CRM 2016, few enhancements were added in this. In this blog, explained about Enhancements of <a href=\"https:\/\/www.inogic.com\/blog\/category\/webapi\/\" target=\"_blank\" rel=\"noopener noreferrer\">Web API<\/a> which is more helpful for the Developers.<\/p>\n<p>Mainly, there are two enhancements released for the Web API Queries.<\/p>\n<p><strong>1. Filtering records based on the Parent entity Attribute<\/strong><\/p>\n<p>In one of our earlier <a href=\"https:\/\/www.inogic.com\/blog\/2016\/01\/querying-data-in-microsoft-dynamics-crm-2016-using-web-api\/\" target=\"_blank\" rel=\"noopener noreferrer\">blog<\/a>, we have explained how to read the records based Lookup field using prefix \u201cunderscore\u201d and suffix \u201cvalue\u201d. But, now with Microsoft Dynamics CRM 2016 update 1 we can filter the records using <strong>Parent entity Attribute<\/strong>.<\/p>\n<p>Suppose, if we want to retrieve the opportunities of a particular Account then we can use the Lookup field name and primary attribute of the Parent entity which helps to retrieve the Opportunities of that Account.<\/p>\n<p>Refer below Query for above example:<\/p>\n<p><strong>Query:<\/strong><\/p>\n<p><strong>https:\/\/[OrganizationURI]\/api\/data\/v8.1\/opportunities $select=name&amp;$filter=parentaccountid\/accountid%20eq%205A544BE0-6217-E611-80DE-C4346BDDC0A1<\/strong><\/p>\n<p><strong>Description:<\/strong><\/p>\n<p><strong>parentaccountid: It is the lookup field name on the Opportunity entity.<\/strong><\/p>\n<p><strong>acountid: It is primary attribute of the Account entity.<\/strong><\/p>\n<p><strong>Response:<a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2016\/05\/Web-API-Enhancements-in-Dynamics-CRM.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-2931\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2016\/05\/Web-API-Enhancements-in-Dynamics-CRM.png\" alt=\"Web API Enhancements in Dynamics CRM\" width=\"626\" height=\"125\" \/><\/a><\/strong><\/p>\n<p>Also, you can refer the below code to run above query using <strong>Ajax<\/strong> request:<\/p>\n<p>\/\/this below code snippet retrieves opportunities of particular Account<\/p>\n<pre class=\"lang:default decode:true \">function retrieveOpportunities() {\r\n    try {\r\n\r\n        \/\/query\r\n        var oDataUrl = Xrm.Page.context.getClientUrl() + \"\/api\/data\/v8.1\/opportunities?$select=name&amp;$filter=parentaccountid\/accountid%20eq%205A544BE0-6217-E611-80DE-C4346BDDC0A1\";\r\n\r\n        \/\/ajax request to retrieve the opportunities of particular account\r\n        $.ajax({\r\n            type: \"GET\",\r\n            contentType: \"application\/json; charset=utf-8\",\r\n            datatype: \"json\",\r\n            url: oDataUrl,\r\n            beforeSend: function (xhr) {\r\n                xhr.setRequestHeader(\"Accept\", \"application\/json\");\r\n                xhr.setRequestHeader(\"Content-Type\", \"application\/json; charset=utf-8\");\r\n                xhr.setRequestHeader(\"OData-MaxVersion\", \"4.0\");\r\n                xhr.setRequestHeader(\"OData-Version\", \"4.0\");\r\n\r\n                xhr.setRequestHeader(\"Prefer\", \"odata.include-annotations=*\");\r\n\r\n            },\r\n            success: function (data, textStatus, xhr) {\r\n                if (data != null) {\r\n\r\n                    if (data.value[0].name != null) {\r\n                        var opportnutyName = data.value[0].name;\r\n                    }\r\n\r\n\r\n                }\r\n            },\r\n            error: function (xhr, textStatus, errorThrown) {\r\n                Xrm.Utility.alertDialog(xhr.statusText);\r\n            }\r\n        });\r\n\r\n    } catch (e) {\r\n        Xrm.Utility.alertDialog(e.message + \"\\n\" + e.description);\r\n    }\r\n}\r\n<\/pre>\n<p><strong>Note: We can only filter the records based on the Primary Attribute of the Parent entity.<\/strong><\/p>\n<p><strong>2. Retrieve Parent Entity attributes by using expand command.<\/strong><\/p>\n<p style=\"text-align: justify;\">As same in our earlier <a href=\"https:\/\/www.inogic.com\/blog\/2016\/01\/querying-data-in-microsoft-dynamics-crm-2016-using-web-api\/\" target=\"_blank\" rel=\"noopener noreferrer\">blog<\/a>, we have explained that we can read the parent entity attributes but in that there was a limitation that we can query for the single record and <strong>not<\/strong> for the collection of records. Now, with the CRM 2016 update 1 we can read the Parent entity attributes in the collection of records using the below query. Suppose, if we are retrieving the all Opportunities and also need to retrieve Account\u2019s City then we can use the below query.<\/p>\n<p style=\"text-align: justify;\">Refer below Query for above example:<\/p>\n<p><strong>Query:<\/strong><\/p>\n<p><strong>https:\/\/[OrganizationURI]\/api\/data\/v8.1\/opportunities?$select=name&amp;$expand=parentaccountid($select=address1_city)<\/strong><\/p>\n<p><strong>Description:<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 expand: It is command to retrieve the parent entity attributes.<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 parentaccountid: It is lookup field name on the Opportunity entity.<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 address1_city: It is field name of the parent entity which is to be retrieved.<\/strong><\/p>\n<p><strong>Response:<a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2016\/05\/Web-API-enhancemnets.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-2932\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2016\/05\/Web-API-enhancemnets.png\" alt=\"Web API enhancemnets\" width=\"626\" height=\"157\" \/><\/a><\/strong><\/p>\n<p><strong>Conclusion:<\/strong><\/p>\n<p>Hope this two enhancement added in Web API Query will be helpful for developers.<\/p>\n<p>We will cover more about Web API in our coming blogs.<\/p>\n<p><span style=\"color: #800000;\">Before you move on to the next post, have a look at <span style=\"color: #0000ff;\"><a style=\"color: #0000ff;\" href=\"http:\/\/bit.ly\/1SAyYIb\" target=\"_blank\" rel=\"noopener noreferrer\">Click2Clone<\/a><\/span> \u2013 New Productivity add-on by Inogic.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: Microsoft Dynamics CRM 2016 introduced a new concept called Web API which can be used across wide variety of devices, programming languages and platforms. With the release of Update 1 for CRM 2016, few enhancements were added in this. In this blog, explained about Enhancements of Web API which is more helpful for the\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2016\/05\/web-api-enhancements-in-dynamics-crm-update-1\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[25,65],"tags":[708,1818,1819],"class_list":["post-2930","post","type-post","status-publish","format-standard","hentry","category-dynamics-crm-2016-update-1","category-webapi","tag-dynamics-crm-web-api","tag-web-api-dynamics-crm-2016","tag-web-api-enhancements"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/2930","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=2930"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/2930\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=2930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=2930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=2930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}