{"id":2216,"date":"2016-01-08T15:19:00","date_gmt":"2016-01-08T09:49:00","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=2216"},"modified":"2016-01-08T15:19:00","modified_gmt":"2016-01-08T09:49:00","slug":"web-api-actions-in-dynamics-crm-2016","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2016\/01\/web-api-actions-in-dynamics-crm-2016\/","title":{"rendered":"Web API Actions in Dynamics CRM 2016"},"content":{"rendered":"<p>Taking forward our series on using WEB API in Microsoft Dynamics CRM 2016, we will now touch upon a feature that was not available in ODATA v2 of the earlier versions.<\/p>\n<p>ODATA v2 only provided support for CRUD operations. But Dynamics CRM has some special messages\/functions for special operations that are beyond the basic CRUD on an entity. To perform these actions in the earlier versions of Microsoft Dynamics CRM, we had to fall back on SOAP messages.<\/p>\n<p>With Web API, actions are now supported. Action is equivalent to requests that are available in Dynamics CRM.<\/p>\n<p>There are predefined Actions defined in Dynamics CRM 2016 that can be executed using Web API. Following is like where you will find the list of Web API actions. <a href=\"https:\/\/msdn.microsoft.com\/en-in\/library\/mt607829.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/msdn.microsoft.com\/en-in\/library\/mt607829.aspx<\/a><\/p>\n<p>There are three types of Action as listed below.<\/p>\n<ol>\n<li>Unbound actions: It is not bound to any specific entity. i.e the first parameter to such actions does not include the entity. E.g. WinOpportunity, CancelContract etc<\/li>\n<li>Bound actions: It is bound to specific entity. i.e the first parameter to such actions does not include the entity. e.g. &#8211; AddToQueue Action<\/li>\n<li>Custom action: It is custom actions developed by developers using Processes.<\/li>\n<\/ol>\n<p>We are explaining Web API Action called <strong>ConvertSalesOrderToInvoice<\/strong> which corresponds to the organization service <strong>ConvertSalesOrderToInvoiceRequest<\/strong>. <strong>ConvertSalesOrderToInvoice<\/strong> action is not bound to any entity and does not return a value. <strong>ConvertSalesOrderToInvoice<\/strong> Action require following parameters.<\/p>\n<p><strong>SalesOrderId<\/strong>: Guid of the order to convert. (This is compulsory parameter)<\/p>\n<p><strong>ColumnSet<\/strong>: List of attributes to retrieve from the created invoice. (This is compulsory parameter)<\/p>\n<p>Below is the code that are used to execute <strong>ConvertSalesOrderToInvoice<\/strong> Action.<\/p>\n<p>\/\/This function is used execute the standard action of webAPI<\/p>\n<p>Here is the main Ajax request that execute the Action.<\/p>\n<pre class=\"lang:default decode:true\">function executeAction() {\n\n\u00a0\u00a0\u00a0 var saleOrderID = null;\n\n\u00a0\u00a0\u00a0 var columnsSet = null;\n\n\u00a0\u00a0\u00a0 try {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/set the param values\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 saleOrderID = \"D035DD97-3AB5-E511-80E2-6C3BE5A852B0\";\u00a0\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0columnsSet = new Array(\"name\", \"totalamount\");\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/create the action object\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 var actionObj = {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"SalesOrderId\": saleOrderID,\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\"ColumnSet\":\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\n\n'AllColumns': false,\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 'Columns': columnsSet\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 },\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 };\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ call this function to execute the action. Please note the () used along with the function name\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Inogic.ApiLib.execute(actionObj, \"ConvertSalesOrderToInvoice()\", function (data) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ open the Created invoice record\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Xrm.Utility.openEntityForm(\"invoice\", data.invoiceid);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}, function (error) { throw new Error(error.message);\n\n\u00a0\u00a0\u00a0 } catch (e) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 alert(e.message);\n\n\u00a0\u00a0\u00a0 }\n\n}<\/pre>\n<p>\/\/This function is used to execute the Web API Action<\/p>\n<pre class=\"lang:default decode:true\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0execute: function (req, reqName, successCallback, errorCallback) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/create AJAX request\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $.ajax({\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 type: \"POST\",\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 contentType: \"application\/json; charset=utf-8\",\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 datatype: \"json\",\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 url: encodeURI(this.getWebAPIPath() + reqName),\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 data: window.JSON.stringify(req),\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 beforeSend: function (xhr) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/Specifying this header ensures that the results will be returned as JSON.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0xhr.setRequestHeader(\"Accept\", \"application\/json\");\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0xhr.setRequestHeader(\"Content-Type\", \"application\/json; charset=utf-8\");\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 xhr.setRequestHeader(\"OData-MaxVersion\", \"4.0\");\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 xhr.setRequestHeader(\"OData-Version\", \"4.0\");\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 },\n\n\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0success: function (data, textStatus, xhr) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/successCallback function\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 successCallback(data);\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 },\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 error: function (xhr, textStatus, errorThrown) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 errorCallback(Inogic.ApiLib.errorHandler(xhr));\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }});\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 },<\/pre>\n<p>\/\/This function is used to get the client URL<\/p>\n<pre class=\"lang:default decode:true  \">\u00a0\u00a0 getClientUrl: function () {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/Get the organization URL\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (typeof GetGlobalContext == \"function\" &amp;&amp;\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 typeof GetGlobalContext().getClientUrl == \"function\") {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return GetGlobalContext().getClientUrl();\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/pre>\n<p>Similar to this you can execute any Web API actions that are listed and your custom action that you developed.<\/p>\n<p><strong>Conclusion:<\/strong><\/p>\n<p>Web API can be used for executing messages other than CRUD as well.<\/p>\n<p>Everything in <strong>Maplytics &#8211; Dynamics CRM and Bing Maps integration<\/strong> is now a search away at our <a href=\"https:\/\/www.inogic.com\/blog\/maplytics-infocentre\/\" target=\"_blank\" rel=\"noopener noreferrer\">Maplytics InfoCentre<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Taking forward our series on using WEB API in Microsoft Dynamics CRM 2016, we will now touch upon a feature that was not available in ODATA v2 of the earlier versions. ODATA v2 only provided support for CRUD operations. But Dynamics CRM has some special messages\/functions for special operations that are beyond the basic CRUD\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2016\/01\/web-api-actions-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-2216","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\/2216","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=2216"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/2216\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=2216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=2216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=2216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}