locked
problem in calling workflow with javascript. plz help me. RRS feed

  • Question

  • this is my code. for test  put it , on save event form of entity wit name'itemsclaim'.   

    the name of entity that my workfolw , is made base on that is 'claim'

    i should say , i  have not built  any websevice for this cod at all.

     

    var   workflowId ="5DF76028-DC06-4BD4-8506-404F8B734DB5";

    var      entityId = crmForm.ObjectId;   // id if 'itemes claim' entity

     

    ExecuteWorkflow = function(entityId, workflowId)
    {
    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\">" +
    GenerateAuthenticationHeader() +
    " <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);
    }

    /* call */
    var theWorkflowId = "<my workflow id>"; //change to your workflow Id
    ExecuteWorkflow(crmForm.ObjectId, theWorkflowId);

    Friday, April 27, 2012 9:47 AM

Answers

  • you are welcome !! , I will appriciate if you will close this thread if you got your solution.

    Mahain : Check My Blog
    Follow me on Twitter
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    • Marked as answer by shabnam2012 Sunday, April 29, 2012 5:18 PM
    Saturday, April 28, 2012 8:20 AM
    Moderator

All replies

  • code looks gud,Are you getting any error ??


    Mahain : Check My Blog
    Follow me on Twitter
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Friday, April 27, 2012 9:54 AM
    Moderator
  • no  there isnt any error
    Friday, April 27, 2012 10:01 AM
  • Make sure asyn is running, because asyn service is responsible for running workflow.

    Mahain : Check My Blog
    Follow me on Twitter
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Friday, April 27, 2012 10:07 AM
    Moderator
  • how can i check that, my workflow automaticly work right, but here dosent work
    Friday, April 27, 2012 10:12 AM
  • i should say, my work flow is mad base on 'claim' entity , and i wanna execute that when i am in 'itemsclaim' entity, isnt no problem for this structure,

    in entity id varible , i should set which entity id?

    Friday, April 27, 2012 10:17 AM
  • you should pass entity id on which workflow is created, so you need to pass claim entity id, you need to get claim record id first and then pass it from here.


    Mahain : Check My Blog
    Follow me on Twitter
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Friday, April 27, 2012 10:33 AM
    Moderator
  • Hello,

    In case some error appeared it would be returned in the response. So to recheck that workflow was triggered you can use following approach:

    alert(ExecuteWorkflow(crmForm.ObjectId, theWorkflowId));


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter

    Friday, April 27, 2012 11:24 AM
    Moderator
  • thank you.  Mahender Pal
    Saturday, April 28, 2012 7:37 AM
  • you are welcome !! , I will appriciate if you will close this thread if you got your solution.

    Mahain : Check My Blog
    Follow me on Twitter
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    • Marked as answer by shabnam2012 Sunday, April 29, 2012 5:18 PM
    Saturday, April 28, 2012 8:20 AM
    Moderator