{"id":4148,"date":"2016-12-20T16:17:14","date_gmt":"2016-12-20T10:47:14","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=4148"},"modified":"2022-07-21T12:17:55","modified_gmt":"2022-07-21T06:47:55","slug":"execute-action-with-entitycollection-parameter-using-web-api-in-dynamics-365","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2016\/12\/execute-action-with-entitycollection-parameter-using-web-api-in-dynamics-365\/","title":{"rendered":"Execute Action with \u201cEntityCollection\u201d Parameter using Web API in Dynamics 365"},"content":{"rendered":"<p><strong>Introduction<\/strong><\/p>\n<p style=\"text-align: justify;\">Recently, we had a requirement where we wanted to Execute Custom Action in Dynamics CRM by passing \u201cEntityCollection\u201d type parameter using Web API. We have discussed how to execute the action using Web API in one of our earlier <a href=\"https:\/\/www.inogic.com\/blog\/2016\/10\/execute-the-global-action-using-web-api-in-dynamics-crm\/\" target=\"_blank\" rel=\"noopener noreferrer\">blog<\/a>. However, in this blog we just explained executing action with string parameter.<\/p>\n<p style=\"text-align: justify;\">Here we are going to focus on executing action with \u201cEntityCollection\u201d parameter using Web API.<\/p>\n<p style=\"text-align: justify;\">You can see below that we have created a Custom Action:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-4149\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2016\/12\/15.jpg\" alt=\"Dynamics CRM Web API\" width=\"665\" height=\"249\" \/><\/p>\n<p style=\"text-align: justify;\"><strong>Below code snippet will help you to Execute Action using Web API:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">function CallCustomActionWithEntityCollectionParameter() {\r\n    try {\r\n\r\n        var reqName = \"new_Approve\";\r\n        var clientUrl = Xrm.Page.context.getClientUrl();\r\n        var parameters = {\r\n           \"Accounts\":\/\/EntityCollection parameter\r\n             [\r\n                  {\r\n                      \"@odata.type\": \"Microsoft.Dynamics.CRM.account\",\/\/entity type\r\n                      \"accountid\": \"C4CA0B66-59B9-E611-8106-C4346BDC0E01\",\/\/Record's guid\r\n                      \"name\": \"Test\",\/\/name field of the account entity\r\n                      \"accountnumber\": \"123\"\/\/accountnumber field of the account entity\r\n                  },\r\n                  {\r\n                      \"@odata.type\": \"Microsoft.Dynamics.CRM.account\",\r\n                      \"accountid\": \"CD67D78E-16BB-E611-8109-C4346BDC3C21\",\r\n                      \"name\": \"Test2\",\r\n                      \"accountnumber\": \"1234\"\r\n                  }\r\n             ]\r\n        };\r\n\r\n        \/\/Create request\r\n        var req = new XMLHttpRequest();\r\n        req.open(\"POST\", clientUrl + \"\/api\/data\/v8.2\/\" + reqName, true);\r\n        req.setRequestHeader(\"Accept\", \"application\/json\");\r\n        req.setRequestHeader(\"Content-Type\", \"application\/json; charset=utf-8\");\r\n        req.setRequestHeader(\"OData-MaxVersion\", \"4.0\");\r\n        req.setRequestHeader(\"OData-Version\", \"4.0\");\r\n\r\n        req.onreadystatechange = function () {\r\n\r\n            if (this.readyState == 4 \/* complete *\/) {\r\n                req.onreadystatechange = null;\r\n\r\n                if (this.status == 200 || this.status == 204) {\r\n                    \/\/success callback   \r\n                    console.log(\"Success\");\r\n                } else {\r\n                    \/\/error callback      \r\n                    console.log(\"Error\");\r\n                }\r\n            }\r\n        };\r\n        req.send(JSON.stringify(parameters));\r\n\r\n    } catch (e) {\r\n        alert(e.message);\r\n    }\r\n}<\/pre>\n<p><strong>Conclusion:<\/strong><\/p>\n<p style=\"text-align: justify;\">This blog will help you to execute action by passing \u201cEntityCollection\u201d parameter using Web API in Dynamics 365.<\/p>\n<h2 style=\"text-align: left;\"><div class=\"su-heading su-heading-style-default su-heading-align-center\" id=\"\" style=\"font-size:15px;margin-bottom:5px\"><div class=\"su-heading-inner\">70% of global 2000 companies apply gamification to improve productivity and returns!<\/div><\/div><\/h2>\n<p><em><strong><a href=\"https:\/\/bit.ly\/3RD4lYW\" target=\"_blank\" rel=\"noopener noreferrer\">Gamifics365<\/a> <\/strong>\u2013 Spin the magic of games within Microsoft Dynamics 365 CRM to improve user adoption, enhance productivity, and achieve company goals!<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Recently, we had a requirement where we wanted to Execute Custom Action in Dynamics CRM by passing \u201cEntityCollection\u201d type parameter using Web API. We have discussed how to execute the action using Web API in one of our earlier blog. However, in this blog we just explained executing action with string parameter. Here we\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2016\/12\/execute-action-with-entitycollection-parameter-using-web-api-in-dynamics-365\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":4158,"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,65],"tags":[591,708],"class_list":["post-4148","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dynamics-365","category-webapi","tag-dynamics-365-web-api","tag-dynamics-crm-web-api"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/4148","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=4148"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/4148\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media\/4158"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=4148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=4148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=4148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}