Execute a workflow using Xrm.WebApi.online.execute method via JavaScript in Dynamics 365 CRM v9

By | May 10, 2019


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 would create a task in our CRM related to the current account when it’s triggered by a JavaScript function.

Note: Make sure to keep your existing custom workflow available to run as an on-demand process.

JavaScript in Dynamics 365 CRM v9

Now with the help of execute request we are going to trigger that workflow.

Solution: Following is the piece of code to achieve the above objective.


In the above piece of code, we have created a dynamics request object named “ExecuteCustomWorkflowRequest” 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:

JavaScript in Dynamics 365 CRM v9

Once the “triggerCustomWorkflowRequest” request is built, we would pass it to execute method which would then invoke “ExecuteWorkflow” action. This action will execute our workflow to create task related to the account record whose id was passed in the “triggerCustomWorkflowRequest” request.

Upon execution of our custom workflow via execute method, following task is created.

JavaScript in Dynamics 365 CRM v9

Also, following is a link to execute workflow via HTTP Request: https://www.inogic.com/blog/2016/11/execute-workflow-using-web-api-in-dynamics-365-2/

For more information on execute method visit the following link: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/xrm-webapi/online/execute

You can find complete list of WebApi actions here:  https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/actions?view=dynamics-ce-odata-9

Hope it helps.

Cut short 90% of your manual work and repetitive data entry!

Get 1 Click apps and say goodbye to all repetitive data entry in CRM –
Click2Clone – Clone/Copy Dynamics 365 CRM records in 1 Click
Click2Export – Export Dynamics 365 CRM Report/CRM Views/Word/Excel template in 1 Click
Click2Undo – Undo & Restore Dynamics 365 CRM data in 1 Click

4 thoughts on “Execute a workflow using Xrm.WebApi.online.execute method via JavaScript in Dynamics 365 CRM v9


    The getMetadata typeName for the workflow is incorrect. It should be “mscrm.workflow”

    1. inogic

      Thanks for your comment.

      Type name “mscrm” is an alias for Microsoft.Dynamics.CRM as shown in below screenshot. So we can use both “Microsoft.Dynamics.CRM” and “mscrm” as a typeName for workflow.



      Hope this helps.


  2. Tim Williams

    Does the success callback execute once the workflow has been completely executed or rather when the workflow is determined to be able to be successfully executed?

Comments are closed.