{"id":18429,"date":"2019-05-10T09:23:02","date_gmt":"2019-05-10T09:23:02","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=18429"},"modified":"2021-12-15T16:17:16","modified_gmt":"2021-12-15T10:47:16","slug":"execute-workflow-using-xrm-webapi-online-execute-method-via-javascript-in-dynamics-365-crm-v9","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2019\/05\/execute-workflow-using-xrm-webapi-online-execute-method-via-javascript-in-dynamics-365-crm-v9\/","title":{"rendered":"Execute a workflow using Xrm.WebApi.online.execute method via JavaScript in Dynamics 365 CRM v9"},"content":{"rendered":"<h2><strong>Introduction<\/strong><\/h2>\n<p>In this blog, we are going to create a request using ExecuteWorkflow action and would execute the request that would execute a custom workflow. This approach would eliminate the need to create an Ajax request and is supported across web client, UCI and Mobile.<\/p>\n<p>For demonstration purpose, we have created a custom workflow. This would create a task in our CRM related to the current account when it\u2019s triggered by a JavaScript function.<\/p>\n<blockquote><p><strong>Note:<\/strong> Make sure to keep your existing custom workflow available to run as an on-demand process.<\/p><\/blockquote>\n<p style=\"padding-left: 40px;\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-18430\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/05\/1JavaScript-in-Dynamics-365-CRM-v9.png\" alt=\"JavaScript in Dynamics 365 CRM v9\" width=\"649\" height=\"235\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/05\/1JavaScript-in-Dynamics-365-CRM-v9.png 649w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/05\/1JavaScript-in-Dynamics-365-CRM-v9-300x109.png 300w\" sizes=\"(max-width: 649px) 100vw, 649px\" \/><\/p>\n<p>Now with the help of execute request we are going to trigger that workflow.<\/p>\n<p><strong>Solution: <\/strong>Following is the piece of code to achieve the above objective.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-18434\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/05\/javascript.jpg\" alt=\"javascript\" width=\"731\" height=\"457\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/05\/javascript.jpg 731w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/05\/javascript-300x188.jpg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/05\/javascript-660x413.jpg 660w\" sizes=\"(max-width: 731px) 100vw, 731px\" \/><\/p>\n<p>In the above piece of code, we have created a dynamics request object named \u201cExecuteCustomWorkflowRequest\u201d and we have passed current account id to it along with workflow id. We would recommend to retrieve workflow id dynamically. As of now, we have passed hard coded workflow id for demonstration purpose, which can be found in the URL of workflow as highlighted in blue colour in the following screenshot:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-18431\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/05\/2JavaScript-in-Dynamics-365-CRM-v9.png\" alt=\"JavaScript in Dynamics 365 CRM v9\" width=\"1036\" height=\"48\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/05\/2JavaScript-in-Dynamics-365-CRM-v9.png 1036w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/05\/2JavaScript-in-Dynamics-365-CRM-v9-300x14.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/05\/2JavaScript-in-Dynamics-365-CRM-v9-768x36.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/05\/2JavaScript-in-Dynamics-365-CRM-v9-1024x47.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/05\/2JavaScript-in-Dynamics-365-CRM-v9-660x31.png 660w\" sizes=\"(max-width: 1036px) 100vw, 1036px\" \/><\/p>\n<p>Once the \u201c<strong>triggerCustomWorkflowRequest<\/strong>\u201d request is built, we would pass it to execute method which would then invoke \u201c<strong>ExecuteWorkflow<\/strong>\u201d action. This action will execute our workflow to create task related to the account record whose id was passed in the \u201ctriggerCustomWorkflowRequest\u201d request.<\/p>\n<p>Upon execution of our custom workflow via execute method, following task is created.<\/p>\n<p style=\"padding-left: 40px;\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-18432\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/05\/3JavaScript-in-Dynamics-365-CRM-v9.png\" alt=\"JavaScript in Dynamics 365 CRM v9\" width=\"712\" height=\"279\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/05\/3JavaScript-in-Dynamics-365-CRM-v9.png 712w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/05\/3JavaScript-in-Dynamics-365-CRM-v9-300x118.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/05\/3JavaScript-in-Dynamics-365-CRM-v9-660x259.png 660w\" sizes=\"(max-width: 712px) 100vw, 712px\" \/><\/p>\n<p>Also, following is a link to execute workflow via HTTP Request: <a href=\"https:\/\/www.inogic.com\/blog\/2016\/11\/execute-workflow-using-web-api-in-dynamics-365-2\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/www.inogic.com\/blog\/2016\/11\/execute-workflow-using-web-api-in-dynamics-365-2\/<\/a><\/p>\n<p>For more information on execute method visit the following link: <a href=\"https:\/\/docs.microsoft.com\/en-us\/dynamics365\/customer-engagement\/developer\/clientapi\/reference\/xrm-webapi\/online\/execute\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/docs.microsoft.com\/en-us\/dynamics365\/customer-engagement\/developer\/clientapi\/reference\/xrm-webapi\/online\/execute<\/a><\/p>\n<p>You can find complete list of WebApi actions here:\u00a0 <a href=\"https:\/\/docs.microsoft.com\/en-us\/dynamics365\/customer-engagement\/web-api\/actions?view=dynamics-ce-odata-9\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/docs.microsoft.com\/en-us\/dynamics365\/customer-engagement\/web-api\/actions?view=dynamics-ce-odata-9<\/a><\/p>\n<p>Hope it helps.<\/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 this blog, we are going to create a request using ExecuteWorkflow action and would execute the request that would execute a custom workflow. This approach would eliminate the need to create an Ajax request and is supported across web client, UCI and Mobile. For demonstration purpose, we have created a custom workflow. This\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2019\/05\/execute-workflow-using-xrm-webapi-online-execute-method-via-javascript-in-dynamics-365-crm-v9\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":18480,"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":[33,65],"tags":[1868,1813],"class_list":["post-18429","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","category-webapi","tag-javascript-dynamics-365-crm-v9","tag-web-api"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/18429","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=18429"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/18429\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media\/18480"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=18429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=18429"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=18429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}