web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

how does one call workflow from javascript

(0) ShareShare
ReportReport
Posted on by

please provide a specific example and do you do it on-change on-load etc

*This post is locked for comments

I have the same question (0)
  • Rahul G J Profile Picture
    605 on at

    Try this,  this might help you :

    Process.callWorkflow(<Input workflow GUID>,

       Xrm.Page.data.entity.getId(),

       function () {

           alert("Workflow executed successfully");

       },

       function () {

           alert("Error executing workflow");

       });

    If this helps please mark the answer verified. :)

  • Rahul G J Profile Picture
    605 on at

    Try this,  this might help you :

    Process.callWorkflow(<Input workflow GUID>,

      Xrm.Page.data.entity.getId(),

      function () {

          alert("Workflow executed successfully");

      },

      function () {

          alert("Error executing workflow");

      });

    If this helps please mark the answer verified. :)

  • nghieppham Profile Picture
    4,755 on at

    Hi,

    Please download this js tool processjs.codeplex.com.

    And then you can use the code that Rahul recommended.

    Regards,

  • Community Member Profile Picture
    on at

    thanks

    here is my issue  

    from a custom address entity, once i create an address I then update the corresponding related contact record associated with that person to add the address ( there is a subgrid on the contact page displaying the address)  there is a realtime workflow on the address entity that runs once the address is created

    if the address entered is their main address, there are fields on the contact record besides the  subgrid that get updated by the workflow to display the main address

    my issue is once i enter an address I need to run the workflow, wait till it completes, then do a data refresh of the page

    I am told i need to call the workflow via javascript  

    I am not sure how to do this I did use this code but get error executing workflow

    from my situation i just discribed how would this be handled  and would anything be added like a custom button or anything to do so  I  am just not clear on a good approach to handle this problem  

    i tried doing a subgrid refresh check on the contact record which did work somewhat but if someone sorted the grid the refresh happened each time

    any advice would be great

  • Inogic Profile Picture
    748 on at

    Try this code :

     

    //function to run the workflow

    function RunWorkflow() {

        try {

            if (Xrm != 'undefined' && Xrm != null) {

                var entityId = Xrm.Page.data.entity.getId();

                alert("entityId: " + entityId);

                if (entityId != 'undefined' && entityId != null) {

                    TriggerWorkflow(entityId);

                }

            }

        } catch (e) {

            alert("RunWorkflow error >> " + e.description);

        }

    }

     

     

     

    function TriggerWorkflow(entityId) {

        /*Generate Soap Body.*/

     

        var request = "" + "<request i:type='b:ExecuteWorkflowRequest' xmlns:a='schemas.microsoft.com/.../Contracts' xmlns:b='schemas.microsoft.com/.../Contracts'>"

            + "<a:Parameters xmlns:c='schemas.datacontract.org/.../System.Collections.Generic'>"

              + "<a:KeyValuePairOfstringanyType>"

                + "<c:key>EntityId</c:key>"

                + "<c:value i:type='d:guid' xmlns:d='schemas.microsoft.com/.../Serialization'>" + entityId + "</c:value>"

              + "</a:KeyValuePairOfstringanyType>"

              + "<a:KeyValuePairOfstringanyType>"

                + "<c:key>WorkflowId</c:key>"

                + "<c:value i:type='d:guid' xmlns:d='schemas.microsoft.com/.../Serialization'>5AE89DDD-8F82-4A50-9A56-771A6CF9778B</c:value>"

              + "</a:KeyValuePairOfstringanyType>"

            + "</a:Parameters>"

            + "<a:RequestId i:nil='true' />"

            + "<a:RequestName>ExecuteWorkflow</a:RequestName>"

          + "</request>";

        try {

            //Call the function to execute the workflow

            XrmServiceToolkit.Soap.Execute(request);

        } catch (e) {

            alert("TriggerWorkflow error >> " + e.description);

        }

    }

     

    Note: The below code uses XrmServiceToolkit. Please find the same at the following link https://xrmservicetoolkit.codeplex.com/

     

    In the above code you need to pass Workflow Id/Guid as we passed here “5AE89DDD-8F82-4A50-9A56-771A6CF9778B”.

    Thanks,

    Sam

  • Suggested answer
    Brad Sprigg Profile Picture
    985 on at

    Hi there

    You could also look at doing this by Actions, which you can then fire off via Javascript using Web API, if you are looking for a native solution.,

    Regards

    Brad

  • Priyesh Profile Picture
    7,396 User Group Leader on at

    Hi,

    Is this supported configuration and is available in Dynamics CRM SDK? Please advise. Thanks.

  • Suggested answer
    Community Member Profile Picture
    on at

    Solution for Dynamics 365 (triggering workflow from JavaScript)

    The workflow should be  on-demand process

     

    First get the Workflow id using the below code

    var workFlowName = "myWorkFlow";

    var  workFlowId = "";

    var xmlData = Xrm.Page.context.getClientUrl() + '/XRMServices/2011/OrganizationData.svc/WorkflowSet?$select=WorkflowId&$filter=StateCode/Value eq 1 and ParentWorkflowId/Id eq null and Name eq \'' + workFlowName + '\'';

     var xmlHttp = new XMLHttpRequest();

     xmlHttp.open("GET", xmlData, false);

     xmlHttp.send();

     if (xmlHttp.status == 200) {

         var result = xmlHttp.responseText;

         workFlowId = //------ (write logic to parse workflow id from xmlHttp object)

     }

     

    Now Trigger the Work Flow

    var functionName = "executeWorkflow >>";

     var query = "workflows(" + workflowId.replace("}", "").replace("{", "") + ")/Microsoft.Dynamics.CRM.ExecuteWorkflow";

     

     var data = {

         "EntityId": accountId

     };

     

     var req = new XMLHttpRequest();

     

     req.open("POST", encodeURI(Xrm.Page.context.getClientUrl() + "/api/data/v8.1/" + query), true);

     

     req.setRequestHeader("Accept", "application/json");

     req.setRequestHeader("Content-Type", "application/json; charset=utf-8");

     req.setRequestHeader("OData-MaxVersion", "4.0");

     req.setRequestHeader("OData-Version", "4.0");

     

     req.onreadystatechange = function() {

     

         if (this.readyState == 4 /* complete */ ) {

             if (this.status == 204) {

                 //success callback this returns null since no return value available.    

             } else {

                 //error callback

             }

         }

     };

     req.send(JSON.stringify(data));

    The above code works perfectly, hope it helps!

     

     

     

  • Suggested answer
    Summer Garg Profile Picture
    585 on at

    Hi luckylifestyledesigner,

    Check this post, to execute workflow using java-script.

    crmhub.blogspot.in/.../execute-workflow-using-java-script-MS-Dynamic-CRM.html

  • Community Member Profile Picture
    on at

    This method is giving me error on req.send

    error message: Failed to load resource: the server responded with a status of 404 ()

    entityID and workflow id are correct and workflow is in activated state.

    Please help.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans