{"id":2389,"date":"2016-02-03T17:18:48","date_gmt":"2016-02-03T11:48:48","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=2389"},"modified":"2026-02-09T12:49:46","modified_gmt":"2026-02-09T07:19:46","slug":"web-api-functions-in-dynamics-crm-2016","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2016\/02\/web-api-functions-in-dynamics-crm-2016\/","title":{"rendered":"Web API functions in Dynamics CRM 2016"},"content":{"rendered":"<p>The Web API which is introduced in Microsoft Dynamics CRM 2016 enhances the experience while developing through different programming languages, devices and platforms. It implements the OData, version 4.0, an OASIS standard which is used to build as well as to consume Restful APIs over rich data sources.<\/p>\n<p>There are predefined functions introduced in the Web API which when executed help you to retrieve data. They may have parameters and they may return values. Functions may be bound to a specific entity. You will find the list of Web API functions on the web page: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/mt607866.aspx.\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/msdn.microsoft.com\/en-us\/library\/mt607866.aspx<\/a><\/p>\n<p>Let\u2019s take an example of <strong>RetrieveVersion<\/strong> function<\/p>\n<p>The<strong> RetrieveVersion <\/strong>function is used to get the version number of Microsoft Dynamics CRM Server. It is similar to the RetrieveVersionRequest which is used to get the version number through organization services.<\/p>\n<p>The function is not bound to any entity types and does not require any parameters.<\/p>\n<p>Here is the code for executing the standard functions of the WebAPI.<\/p>\n<pre class=\"lang:default decode:true \">\/\/This function is used execute the standard functions of webAPI\r\n\r\nfunction exeFunction() {\r\n    try {\r\n        Inogic.ApiLib.executeFunction(\"RetrieveVersion()\", exeFunctionSucess, function(error){throw new Error(error.message)};\r\n\r\n    } catch (e) {\r\n        showMessage(e.message);\r\n    }\r\n}\r\n\r\n\/\/success call back\r\nfunction exeFunctionSucess(data) {\r\n    try {\r\n\r\n        var versionNumber = data;\r\n    }\r\n    catch (e) {\r\n        showMessage(e.message);\r\n    }\r\n}<\/pre>\n<p>Here is the main code for executing the functions and fetching the results.<\/p>\n<pre class=\"lang:default decode:true \">\/\/ This function is used to execute the function and get the results\r\n \r\n            executeFunction: function (funName, successCallback, errorCallback) {\r\n\r\n                \/\/create the AJAX request\r\n                $.ajax({\r\n                    type: \"GET\",\r\n                    contentType: \"application\/json; charset=utf-8\",\r\n                    datatype: \"json\",                  \r\n                    url: encodeURI(this.getWebAPIPath() + funName),                   \r\n                    beforeSend: function (xhr) {\r\n                        \r\n\/\/ This header ensures that the results will be returned as JSON.   \r\n          \r\n                        xhr.setRequestHeader(\"Accept\", \"application\/json\");                    \r\n                     \r\n\/\/xhr.setRequestHeader(\"Content-Type\", \"application\/json; charset=utf-8\");\r\n\r\n                        xhr.setRequestHeader(\"OData-MaxVersion\", \"4.0\");\r\n                        xhr.setRequestHeader(\"OData-Version\", \"4.0\");\r\n                    },\r\n                    success: function (data, textStatus, xhr) {\r\n\r\n                        \/\/successCallback function - Here you get the version number.\r\n\r\n                        successCallback(data.Version);\r\n                    },\r\n                    error: function (xhr, textStatus, errorThrown) {\r\n                        errorCallback(Inogic.ApiLib.errorHandler(xhr));\r\n                    }\r\n                });\r\n\r\n            }<\/pre>\n<p><strong>Web API Query Functions:<\/strong><\/p>\n<p>Query functions are those which are used to add a filter criteria in Odata query. These functions accept parameters and return a Boolean value. It serves to be an additional filter applied on Odata query.<\/p>\n<p>You would find predefined query functions of Web API in the following link. <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/mt607843.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/msdn.microsoft.com\/en-us\/library\/mt607843.aspx<\/a><\/p>\n<p>Let us consider ThisYear Function. It is used to retrieve data within the current year. It accepts parameter as property name (date attribute name) and returns data within this year.<\/p>\n<p><em>Note: This function only accepts Date Datatype as a parameter. If you pass a parameter other than the date, then it throws an error.<\/em><\/p>\n<pre class=\"lang:default decode:true \">\/\/ This function is used to execute the query function \r\n\r\nfunction executeQueryFunction() {\r\n\r\n    var query = null;\r\n\r\n    try {\r\n\r\n        \/\/ create the query\r\n\r\n        query = \"?$select=accountcategorycode,accountnumber,creditonhold,createdon,numberofemployees,name,revenue\";\r\n\r\n        \/\/ add the query function\r\n \r\n        query += \"&amp;$filter=Microsoft.Dynamics.CRM.ThisYear(PropertyName='modifiedon')\";\r\n\r\n        \/\/query += \"&amp;$filter=Microsoft.Dynamics.CRM.Today(PropertyName='modifiedon')\";\r\n\r\n        \/\/call this function to execute the query function\r\n        Inogic.ApiLib.executeQueryFunction(\"accounts\", query, executeQueryFunctionSuccess, executeQueryFunctionError, executeQueryFunctionError, false);\r\n\r\n    } catch (e) {\r\n        showMessage(e.message);\r\n    }\r\n}\r\n\r\n\/\/success call back\r\n\r\nfunction executeQueryFunctionSuccess(data) {\r\n    try {\r\n\r\n        \/\/This function is used to process return data\r\n\r\n        processData(data);\r\n\r\n        HideBusyIndicator();\r\n    }\r\n    catch (e) {\r\n        showMessage(e.message);\r\n    }\r\n}<\/pre>\n<p>This is the main Ajax call function.<\/p>\n<pre class=\"lang:default decode:true \">   \/\/ This function is used to retrieve records using WebAPI query function\r\n\r\n            executeQueryFunction: function (entitySetName, query, successCallback, errorCallback, onComplete) {\r\n\r\n                try {\r\n                \r\n                    \/\/create AJAX request\r\n\r\n                    $.ajax({\r\n                        type: \"GET\",\r\n                        contentType: \"application\/json; charset=utf-8\",\r\n                        datatype: \"json\",\r\n                        url: encodeURI(oDataUrl),\r\n                        beforeSend: function (xhr) {\r\n                           \r\n\/\/This header ensures that the results will be returned as JSON. \r\n\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                            xhr.setRequestHeader(\"Prefer\", \"odata.include-annotations=*\");\r\n\r\n                        },\r\n                        success: function (data, textStatus, xhr) {\r\n                            if (data != null) {\r\n                                successCallback(data.value);                              \r\n                            }\r\n                        },\r\n                        error: function (xhr, textStatus, errorThrown) {\r\n                            errorCallback(xhr.statusText);\r\n                        }\r\n                    });\r\n                } catch (e) {\r\n                    throw new Error(e);\r\n                }\r\n\r\n            },<\/pre>\n<p>When you execute the above query then it will return all Accounts which are modified during a particular year.<\/p>\n<p><span style=\"color: #993300;\"><em>Before moving on to the next post, you may like to read about Dynamics CRM and Bing Maps <a style=\"color: #993300;\" href=\"https:\/\/www.maplytics.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">integration<\/a>.<\/em><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Web API which is introduced in Microsoft Dynamics CRM 2016 enhances the experience while developing through different programming languages, devices and platforms. It implements the OData, version 4.0, an OASIS standard which is used to build as well as to consume Restful APIs over rich data sources. There are predefined functions introduced in the\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2016\/02\/web-api-functions-in-dynamics-crm-2016\/\">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":[16,24,25,65],"tags":[708,1222],"class_list":["post-2389","post","type-post","status-publish","format-standard","hentry","category-dynamics-365","category-dynamics-crm-2016","category-dynamics-crm-2016-update-1","category-webapi","tag-dynamics-crm-web-api","tag-ms-dynamics-crm-web-api"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/2389","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=2389"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/2389\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=2389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=2389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=2389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}