{"id":3692,"date":"2016-10-10T17:07:34","date_gmt":"2016-10-10T11:37:34","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=3692"},"modified":"2022-07-01T14:21:53","modified_gmt":"2022-07-01T08:51:53","slug":"execute-the-global-action-using-web-api-in-dynamics-crm","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2016\/10\/execute-the-global-action-using-web-api-in-dynamics-crm\/","title":{"rendered":"Execute the Global Action Using Web API in Dynamics CRM"},"content":{"rendered":"<p><strong>Introduction:<\/strong><\/p>\n<p>We have already discussed how to perform entity specific custom action using Web API in one of our earlier blog. But when we want an action to be performed on multiple entities, we need to create a global action.<\/p>\n<p><strong>Create global action<\/strong><strong>:-<\/strong><\/p>\n<ol>\n<li>Go to <strong>Settings\u00a0\u2192<\/strong>\u00a0<strong>Processes<\/strong>\u00a0\u2192 Click <strong>New<\/strong> then select category as \u201cAction\u201d and entity as \u201cNone(global)\u201d as shown in below screenshot.<a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2016\/10\/Create-global-action-1.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-3693\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2016\/10\/Create-global-action-1.png\" alt=\"Create global action\" width=\"581\" height=\"438\" \/><\/a><\/li>\n<li>Create the input argument (i.e InputParameter) and output argument (i.e. OutputParameter) as per below screenshot. Save and Activate the action.\u00a0<a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2016\/10\/Create-the-input-argument-2.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-3694\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2016\/10\/Create-the-input-argument-2.png\" alt=\"Create the input argument\" width=\"626\" height=\"444\" \/><\/a><\/li>\n<\/ol>\n<p><strong>Execute Global Action using Web API:-<\/strong><\/p>\n<pre class=\"lang:default decode:true \">Execute the created global action using Web API.\r\n\/\/get the current organization name\r\nvar serverURL = Xrm.Page.context.getClientUrl();\r\n\/\/query to send the request to the global Action \r\nvar query=\u201dnew_GlobalAction\u201d;\r\n\/\/set the current loggedin userid in to _inputParameter of the \r\n_InputParameter=Xrm.Page.context.getUserId();\r\n \r\n\/\/Pass the input parameters of action\r\nvar data = {\r\n\"InputParameter\": _ InputParameter\r\n};\r\n\/\/Create the HttpRequestObject to send WEB API Request \r\nvar req = new XMLHttpRequest(); \r\n\/\/Post the WEB API Request \r\nreq.open(\"POST\", serverURL + \"\/api\/data\/v8.0\/\u201d+query+\", true); \r\nreq.setRequestHeader(\"Accept\", \"application\/json\"); \r\nreq.setRequestHeader(\"Content-Type\", \"application\/json; charset=utf-8\"); \r\nreq.setRequestHeader(\"OData-MaxVersion\", \"4.0\"); \r\nreq.setRequestHeader(\"OData-Version\", \"4.0\"); \r\nreq.onreadystatechange = function() { \r\nif (this.readyState == 4 \/* complete *\/ ) { \r\nreq.onreadystatechange = null; \r\nif (this.status == 200) { \r\n\/\/You can get the output parameter of the action with name as given below\r\nresult = JSON.parse(this.response);\r\nXrm.Page.getAttribute(\u201cFieldname\u201d).setValue(Result.OutputParameter);\r\n} else { \r\nvar error = JSON.parse(this.response).error; \r\nalert(error.message); \r\n} \r\n} \r\n}; \r\n\/\/Execute request passing the input parameter of the action \r\nreq.send(window.JSON.stringify(data));\r\n}<\/pre>\n<p><strong>Note:<\/strong><\/p>\n<p>To execute the global action you only need to pass Action Name \u201c<strong>new_GlobalAction<\/strong>\u201d shown in the above code<\/p>\n<p><strong>req.open(&#8220;POST&#8221;, serverURL + &#8220;\/api\/data\/v8.0\/\u201d+query+&#8221;, true); <\/strong><\/p>\n<p>But to perform entity specific custom action you need to pass the EntityName and Primary id of record as<\/p>\n<p>\u201caccount(&#8221; + Xrm.Page.data.entity.getId() + &#8220;)\/Microsoft.Dynamics.CRM.new_EntityAction \u201d.<\/p>\n<p><strong>Conclusion:<\/strong><\/p>\n<p>Using the above code, global action can be performed. You can perform this action on multiple entities using Web API.<\/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\">Free 70% of storage space in CRM with Attachment Management Apps!<\/div><\/div><\/h2>\n<p><em><strong><a href=\"https:\/\/www.inogic.com\/product\/productivity-apps\/attach-2-dynamics-365-crm-upload-multiple-files-sharepoint-cloud-storage\" target=\"_blank\" rel=\"noopener noreferrer\">Attach2Dynamics<\/a> &#8211; Store and manage documents\/attachments in cloud storage of your choice &#8211; SharePoint, Dropbox or Azure Blob Storage from within Dynamics 365 CRM.<\/strong><\/em><br \/>\n<em><strong><a href=\"https:\/\/www.inogic.com\/product\/productivity-apps\/dynamics-365-crm-sharepoint-security-metadata-sync\" target=\"_blank\" rel=\"noopener noreferrer\">SharePoint Security Sync<\/a><\/strong> \u2013 Robust and secure solution to integrate Dynamics 365 CRM and SharePoint Security Sync thereby ensuring secure access to confidential documents stored in SharePoint.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: We have already discussed how to perform entity specific custom action using Web API in one of our earlier blog. But when we want an action to be performed on multiple entities, we need to create a global action. Create global action:- Go to Settings\u00a0\u2192\u00a0Processes\u00a0\u2192 Click New then select category as \u201cAction\u201d and entity\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2016\/10\/execute-the-global-action-using-web-api-in-dynamics-crm\/\">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":[15,19,24,25,33,65],"tags":[708,755,868,1222],"class_list":["post-3692","post","type-post","status-publish","format-standard","hentry","category-development","category-dynamics-crm","category-dynamics-crm-2016","category-dynamics-crm-2016-update-1","category-javascript","category-webapi","tag-dynamics-crm-web-api","tag-execute-global-action-using-web-api","tag-global-action-using-web-api","tag-ms-dynamics-crm-web-api"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/3692","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=3692"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/3692\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=3692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=3692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=3692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}