locked
How to Trigger OnDemand Workflow using Javascript in MS CRM 2011 RRS feed

  • Question

  • Hi have one req , that to trigger a ondemand workflow by clicking button in from ribbon . So I created a on demand workflow and it works fine. But I need to call that workflow in javascript and need to call the javascript into form  ribbon in ms crm 2011.

    How to achieve this plase help me...

     

    Saturday, December 3, 2011 6:17 AM

Answers

All replies

  • Hi Shetty,

    Have a look at this blog, it may assist you.

    http://andreaswijayablog.blogspot.com/2011/07/crm-2011-custom-button-on-custom-entity.html


    Eric UNG [Senior Analyst Programmer :: Sydney, Australia]
    Saturday, December 3, 2011 10:28 AM
  • Hi.. Sir,

     I created an OnDemand workflow and it works if I mannually select a workflow from the Run Workflow Button.

    But Here I need to Call the wrokflow in JavaScript and it should be trigger When I click a button in the entity form or grid.I followed your link and replaced the workflow id with my ondemand workflow id , but  workflow is not triggering...  Please help me ..how to resolve this..?  Here is the code...

    function TestConvert(SelectedControlSelectedItemReferences)
    {
    alert("RECORD IS CONVERTED ");

         var allItems = new Array();
         var allItems = SelectedControlSelectedItemReferences;
         var iTotal = allItems.length;
       if (iTotal > 0)
         {
           for (var i = 0; i < iTotal; i++)
           {
              alert(allItems[i].Id)
             callworkfow(allItems[i].Id);  
            }
          else
          alert("Please select any record to perform required action");
         }
      }

    function callworkfow(id)
    {  
      try
        {   
        var guid;
        if (id == null)
         {     
          guid = Xrm.Page.data.entity.getId();  
         }     
          else    
           guid = id;

          // assign workflow guid  
         var WorkflowId = "7FAD54F0-454F-4803-9204-78D1458926BA";

     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>" + guid + "</EntityId>" +
    "<workflowid>" + WorkflowId + "</WorkflowId>" + //WorkflowId = guid of the workflow
     "</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;
    if (id == null)
    alert("Success");
    return (resultXml.xml);
    }  
     catch (e)
     {     
      alert("Failed to Execute");
       }
    }

     

    Tuesday, December 6, 2011 12:16 PM