{"id":3896,"date":"2016-11-16T18:23:15","date_gmt":"2016-11-16T12:53:15","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=3896"},"modified":"2021-12-15T16:15:06","modified_gmt":"2021-12-15T10:45:06","slug":"execute-workflow-using-web-api-in-dynamics-365-2","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2016\/11\/execute-workflow-using-web-api-in-dynamics-365-2\/","title":{"rendered":"Execute Workflow using Web API in Dynamics 365"},"content":{"rendered":"<p><strong>Introduction<\/strong>:<\/p>\n<p>In every release, Microsoft comes up with some new and interesting features. With this Dynamics 365 release, the WEB API platform has been enhanced further. Microsoft has introduced many actions using Web API. Here we will see one of those new actions introduced in Dynamics 365 i.e. \u201c<strong>ExecuteWorkflow<\/strong>\u201d.<\/p>\n<p>Until Dynamics CRM 2016 Update 1 (8.1), <strong>ExecuteWorkflowRequest<\/strong> was not available using Web API. But with Dynamics 365 \u201c<strong>ExecuteWorkflow<\/strong>\u201d is now available to us. Now we can execute the workflow using Web API.<\/p>\n<p>Below is the code using which you can execute workflow.<\/p>\n<pre class=\"lang:default decode:true \">function executeWorkflow(accountId, workflowId, clientUrl) {\r\n    var functionName = \"executeWorkflow &gt;&gt;\";\r\n    var query = \"\";\r\n    try {\r\n\r\n        \/\/Define the query to execute the action\r\n        query = \"workflows(\" + workflowId.replace(\"}\", \"\").replace(\"{\", \"\") + \")\/Microsoft.Dynamics.CRM.ExecuteWorkflow\";\r\n\r\n        var data = {           \r\n                \"EntityId\": accountId                         \r\n        };\r\n\r\n        \/\/Create request\r\n       \/\/ request url\r\n       \/\/https:\/\/org.crm.dynamics.com\/api\/data\/v8.2\/workflows(\u201cf0ca33cc-23fd-496f-80e1-693873a951ca\u201d)\/Microsoft.Dynamics.CRM.ExecuteWorkflow\r\n        var req = new XMLHttpRequest();\r\n        req.open(\"POST\", clientUrl + \"\/api\/data\/v8.2\/\" + query, 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) {\r\n                    \/\/success callback this returns null since no return value available.\r\n                    var result = JSON.parse(this.response);\r\n\r\n\r\n                } else {\r\n                    \/\/error callback\r\n                    var error = JSON.parse(this.response).error;\r\n                }\r\n            }\r\n        };\r\n        req.send(JSON.stringify(data));\r\n\r\n    } catch (e) {\r\n        throwError(functionName, e);\r\n    }\r\n}<\/pre>\n<p><strong>Conclusion<\/strong><\/p>\n<p>There are a lot of cases where you add ribbon button to personalize the user experience but behind the scene you are actually executing a workflow. You can now go ahead and get those done through the \u201c<strong>ExecuteWorkflow<\/strong>\u201d action available. We will explore the other actions in later blogs.<\/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\">Cut short 90% of your manual work and repetitive data entry!<\/div><\/div><\/h2>\n<p style=\"text-align: left;\"><em>Get 1 Click apps and say goodbye to all repetitive data entry in CRM &#8211;<\/em><br \/>\n<em><strong><a href=\"https:\/\/bit.ly\/3oH7dYw\" target=\"_blank\" rel=\"noopener noreferrer\">Click2Clone<\/a> <\/strong>\u2013 Clone\/Copy Dynamics 365 CRM records in 1 Click<\/em><br \/>\n<em><strong><a href=\"https:\/\/bit.ly\/3EPjAYc\" target=\"_blank\" rel=\"noopener noreferrer\">Click2Export<\/a><\/strong> \u2013 Export Dynamics 365 CRM Report\/CRM Views\/Word\/Excel template in 1 Click<\/em><br \/>\n<em><strong><a href=\"https:\/\/bit.ly\/3EN8h2v\" target=\"_blank\" rel=\"noopener noreferrer\">Click2Undo<\/a><\/strong> \u2013 Undo &amp; Restore Dynamics 365 CRM data in 1 Click<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: In every release, Microsoft comes up with some new and interesting features. With this Dynamics 365 release, the WEB API platform has been enhanced further. Microsoft has introduced many actions using Web API. Here we will see one of those new actions introduced in Dynamics 365 i.e. \u201cExecuteWorkflow\u201d. Until Dynamics CRM 2016 Update 1\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2016\/11\/execute-workflow-using-web-api-in-dynamics-365-2\/\">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,65],"tags":[758],"class_list":["post-3896","post","type-post","status-publish","format-standard","hentry","category-dynamics-365","category-dynamics-crm-2016","category-webapi","tag-execute-workflow-using-web-api"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/3896","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=3896"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/3896\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=3896"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=3896"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=3896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}