{"id":2134,"date":"2016-03-21T18:13:34","date_gmt":"2016-03-21T18:13:34","guid":{"rendered":"http:\/\/himbap.com\/blog\/?p=2134"},"modified":"2016-03-21T18:13:34","modified_gmt":"2016-03-21T18:13:34","slug":"using-web-api-function-in-crm-2016-part-1","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=2134","title":{"rendered":"Using Web API Function in CRM 2016 Part 1"},"content":{"rendered":"<p>If you are developer, you should be familiar with functions. It is a reusable piece of code which can be used to perform different operation based on their definition. CRM 2016 introduced Web API function which can be used to perform different CRM operations. Following are the two functions available in Web API:<\/p>\n<p>\u2022 <strong>Function<\/strong><br \/>\n\u2022 <strong>Query Function<\/strong><\/p>\n<p>In this article we will be discussing standard function. Web API function is used to retrieve information from CRM, every function basically represents one request in IOrganization service which can return entity collection or complex type. These functions can be generic or can be associated with specific entity, if function is related to specific entity it is known as bound function and if they are generic, not associated with any entity they are known as unbound function. We can get complete list of function reference from <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/mt607866.aspx\">here<\/a>. <\/p>\n<p>We can call function by appending function name with parameters like below:<br \/>\n<em>serverURL + &#8220;\/api\/data\/v8.0\/&#8221;+Functionname(parameter1,parameter2,..n) <\/em><\/p>\n<p>Following is the complete code for using <strong>RetrieveVersion <\/strong>function, which can be used to get current CRM version:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction GetCRMVersion() {\r\n    \/\/get CRM URL\r\n    var serverURL = Xrm.Page.context.getClientUrl();\r\n\r\n    \/\/write request for function  \r\n    var req = new XMLHttpRequest();\r\n    req.open(&quot;GET&quot;, serverURL + &quot;\/api\/data\/v8.0\/RetrieveVersion()&quot;, true);\r\n    req.setRequestHeader(&quot;Accept&quot;, &quot;application\/json&quot;);\r\n    req.setRequestHeader(&quot;Content-Type&quot;, &quot;application\/json; charset=utf-8&quot;);\r\n    req.setRequestHeader(&quot;OData-MaxVersion&quot;, &quot;4.0&quot;);\r\n    req.setRequestHeader(&quot;OData-Version&quot;, &quot;4.0&quot;);\r\n    req.onreadystatechange = function() {\r\n        if (this.readyState == 4 \/* complete *\/ ) {\r\n            req.onreadystatechange = null;\r\n            if (this.status == 200)\/\/check response is OK {\r\n                var data = JSON.parse(this.response);\r\n                alert(&quot;You are using Microsoft Dynamics CRM &quot;+data.Version);\r\n            } else {\r\n                var error = JSON.parse(this.response).error;\r\n                alert(error.message);\r\n            }\r\n        }\r\n    };\r\n    req.send();\r\n}\r\n<\/pre>\n<p>Once we will use execute this code we will get current CRM version, alert like below:<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2016\/03\/currentCRMversion.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-2145 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2016\/03\/currentCRMversion-300x114.png\" alt=\"currentCRMversion\" width=\"300\" height=\"114\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2016\/03\/currentCRMversion-300x114.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2016\/03\/currentCRMversion.png 358w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Stay tuned for more Dynamics CRM updates!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you are developer, you should be familiar with functions. It is a reusable piece of code which can be used to perform different operation based on their definition. CRM 2016 introduced Web API function which can be used to perform different CRM operations. Following are the two functions available in Web API: \u2022 Function \u2022 Query Function In this&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=2134\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":2143,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[21,275,296],"tags":[333,332,334],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2134"}],"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=2134"}],"version-history":[{"count":18,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2134\/revisions"}],"predecessor-version":[{"id":2154,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2134\/revisions\/2154"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/media\/2143"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}