locked
Run workflow from Javascript RRS feed

  • Question

  • I need to run a on demand workflow by a ribbon button click in 2011. I know how to put a button and associate it with a Javascript function.

    My problem is that I don't know how the Javascript code will look like for calling a workflow.

    I tried searching these forums but all the threads are for CRM4.

    Thanks

    Friday, September 23, 2011 10:49 PM

Answers

  • Hi,

    You may try using the following JScript code:

     

    function TriggerWorkflow() {

    var WorkflowId = Workflow_GUID;

    var EntityId = Entity_Record_GUID;

    var xml = "" +

    "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +

    "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +

    Xrm.Page.context.getAuthenticationHeader() +

    "<soap:Body>" +

    "<Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +

    "<Request xsi:type=\"ExecuteWorkflowRequest\">" +

    "<EntityId>" + EntityId + "</EntityId>" +

    "<WorkflowId>" + WorkflowId + "</WorkflowId>" + "</Request>" +

    "</Execute>" +

    "</soap:Body>" +

    "</soap:Envelope>";

    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);

    xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Execute");

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

    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);

    xmlHttpRequest.send(xml);

    var resultXml = xmlHttpRequest.responseXML;

    return (resultXml.xml);

    }


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Edited by Jehanzeb.Javeed Sunday, September 25, 2011 6:31 PM
    • Proposed as answer by Jehanzeb.Javeed Sunday, September 25, 2011 6:32 PM
    • Marked as answer by KatRiketa Tuesday, September 27, 2011 4:51 PM
    Sunday, September 25, 2011 6:31 PM

All replies

  •  

    Here you go buddy

    http://mscrmshop.blogspot.com/2011/06/how-to-start-dialog-from-application_08.html

     Here is call dialog function from the above mentioned blog

    function callDialog() {

        var url="/" + getOrg() + "/cs/dialog/rundialog.aspx?DialogId=%7bB7D825D7-7EF6-4713-AC11-284546FEB260%7d&EntityName=systemuser&ObjectId=" + getUser();
        window.open(url, "", "status=no,scrollbars=no,toolbars=no,menubar=no,location=no");
        //window.open(url);
        }
    
    If you are using crmonline, you don't need getOrg() function. Change the dialogid and entityname according to your system.

     

    I hope this helps.


    Amreek singh Senior CRM Consultant CDC Praxa Sydney,Australia http://mscrmshop.blogspot.com/
    • Edited by Amreek Singh Sunday, September 25, 2011 8:10 AM
    • Proposed as answer by Amreek Singh Sunday, September 25, 2011 8:10 AM
    Saturday, September 24, 2011 1:37 PM
  • Hi,

    You may try using the following JScript code:

     

    function TriggerWorkflow() {

    var WorkflowId = Workflow_GUID;

    var EntityId = Entity_Record_GUID;

    var xml = "" +

    "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +

    "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +

    Xrm.Page.context.getAuthenticationHeader() +

    "<soap:Body>" +

    "<Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +

    "<Request xsi:type=\"ExecuteWorkflowRequest\">" +

    "<EntityId>" + EntityId + "</EntityId>" +

    "<WorkflowId>" + WorkflowId + "</WorkflowId>" + "</Request>" +

    "</Execute>" +

    "</soap:Body>" +

    "</soap:Envelope>";

    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);

    xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Execute");

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

    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);

    xmlHttpRequest.send(xml);

    var resultXml = xmlHttpRequest.responseXML;

    return (resultXml.xml);

    }


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Edited by Jehanzeb.Javeed Sunday, September 25, 2011 6:31 PM
    • Proposed as answer by Jehanzeb.Javeed Sunday, September 25, 2011 6:32 PM
    • Marked as answer by KatRiketa Tuesday, September 27, 2011 4:51 PM
    Sunday, September 25, 2011 6:31 PM
  • I have tried above Jscript code,im not geeting any error message,but my workflow is not executing.

    The workflow send mail.

    Can anyone help me?

    Saturday, October 8, 2011 1:00 PM