Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Call Workflow with input and output parameter from Javascript

Posted on by 390

Hi,

I need to call a workflow with input and output parameter from Javascript in MS CRM 2016. 

I created the workflow and published but I am getting error as "Workflow should be published."

I republished, reset IIS but none made it work.

Please help.

Thanks.

*This post is locked for comments

  • Suggested answer
    Jayakumar Profile Picture
    Jayakumar 390 on at
    RE: Call Workflow with input and output parameter from Javascript

    Hi David Jennaway,

    Thanks. Your response is the correct answer. Even though I have only one workflow with that name CRM internally maintains multiple copies of the same workflow.

    Getting the workflow with activeworkflowid is not null is the correct one.

    Thanks.

  • AHMET TANRIKULU Profile Picture
    AHMET TANRIKULU 225 on at
    RE: Call Workflow with input and output parameter from Javascript

    try to get your workflow id from address bar internet explorer, when your workflow open in a form on the address bar at the end of your workflow guid is there

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Call Workflow with input and output parameter from Javascript

    Is the exact error you are getting: "workflow must be in published state"?

    If it is, see the following:

    community.dynamics.com/.../fixed-workflow-must-be-in-published-state-error-while-converting-case-to-work-order-in-crm

  • Jayakumar Profile Picture
    Jayakumar 390 on at
    RE: Call Workflow with input and output parameter from Javascript

    It is not part of my form script. It is separate Library. I have shown the function I am calling and how I am calling, I want to know if there is any wrong in the calling script.

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Call Workflow with input and output parameter from Javascript

    Hi Jayakumar,

    If you are using the library, then why do you have the entire request in as part of your code. It is unnecessary. The only thing that you need is the part that you specify in Finally...

    Aric

  • Jayakumar Profile Picture
    Jayakumar 390 on at
    RE: Call Workflow with input and output parameter from Javascript

    Hi Aric,

    I am using the same library only. See the code above I posted.

    Thanks.

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Call Workflow with input and output parameter from Javascript

    For calling the workflow, you can download the process.js project. This provides you with easy to use functionality for calling Workflows and Actions in CRM.

    Link is: https://processjs.codeplex.com

    Good luck.

  • Jayakumar Profile Picture
    Jayakumar 390 on at
    RE: Call Workflow with input and output parameter from Javascript

    Its a custom workflow. I removed the input parameter because I don't know how to pass input parameter in the SOAP XML. But still the same issue after removing the input parameter.

  • Jayakumar Profile Picture
    Jayakumar 390 on at
    RE: Call Workflow with input and output parameter from Javascript

    Hi Ahmet,

    This is the library I am using for calling the workflow.

    Process.callWorkflow = function (workflowId, recordId, successCallback, errorCallback, url) {

       debugger;

       if (url == null) {

           url = Xrm.Page.context.getClientUrl();

       }

       var request = "<s:Envelope xmlns:s='schemas.xmlsoap.org/.../&;>" +

             "<s:Body>" +

               "<Execute xmlns='schemas.microsoft.com/.../Services&; xmlns:i='www.w3.org/.../XMLSchema-instance&;>" +

                 "<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/.../&;>" + recordId + "</c:value>" +

                     "</a:KeyValuePairOfstringanyType>" +

                     "<a:KeyValuePairOfstringanyType>" +

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

                       "<c:value i:type='d:guid' xmlns:d='schemas.microsoft.com/.../&;>" + workflowId + "</c:value>" +

                     "</a:KeyValuePairOfstringanyType>" +

                   "</a:Parameters>" +

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

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

                 "</request>" +

               "</Execute>" +

             "</s:Body>" +

           "</s:Envelope>";

       var req = new XMLHttpRequest();

       req.open("POST", url + "/XRMServices/2011/Organization.svc/web", true);

       req.setRequestHeader("Accept", "application/xml, text/xml, */*");

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

       req.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Execute&quot;);

       req.onreadystatechange = function () {

           if (req.readyState == 4) {

               if (req.status == 200) {

                   if (successCallback) {

                       successCallback();

                   }

               }

               else {

                   if (errorCallback) {

                       errorCallback();

                   }

               }

           }

       };

       req.send(request);

    }

    Finally, I am getting the workflow Id from CRM and calling the workflow.

    "/api/data/v8.2/workflows?$select=workflowid&$filter=name eq 'Test Workflow'

    var workflowId = workflow[0].workflowid;

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

    Process.callWorkflow(workflowId, recordId, SuccessCallBack, ErrorCallBack);

  • Jayakumar Profile Picture
    Jayakumar 390 on at
    RE: Call Workflow with input and output parameter from Javascript

    Yes. Activated. Auto triggering is working based on field update. Only calling from JavaScript not working.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans