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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Call Workflow with input and output parameter from Javascript

(0) ShareShare
ReportReport
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

I have the same question (0)
  • ashlega Profile Picture
    34,477 on at

    Hi, have you activated the workflow?

  • AHMET TANRIKULU Profile Picture
    225 on at

    can you share your js code ?

  • David Jennaway Profile Picture
    14,065 on at

    Also, if you're identifying the workflow by the workflowid, make sure you're using the right workflowid, as CRM stores multiple workflow records. See http://mscrmuk.blogspot.co.uk/2011/11/selecting-correct-workflowid.html - the article is a bit dated, but should still be relevant

  • Jayakumar Profile Picture
    390 on at

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

  • Jayakumar Profile Picture
    390 on at

    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
    390 on at

    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.

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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
    390 on at

    Hi Aric,

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

    Thanks.

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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
    390 on at

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans