locked
how to get return guid from javascript when workflow execute in CRM 2013 RRS feed

  • Question

  • Hi,

    I have created a workflow Lead to Opportunity and execute through javascript. My script working record is created in from lead to opportunity. But I want to redirect the page on Opportunity where record is created. Please tell me how to get return guid and redirect page from lead to opportunity?

    function RunWorkflow() {
     var entityId = Xrm.Page.data.entity.getId().substring(1, 37); //Guid of record that workflow is to run on.
    var workflowId = "2ACE5392-98AF-4BF9-ACBD-4419F3A6C9FD"; //Workflow Guid.
    var url = Xrm.Page.context.getClientUrl();

        var OrgServicePath = "/XRMServices/2011/Organization.svc/web";
        url = url + OrgServicePath;
        var request;
        request = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
      "<s:Body>" +
        "<Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">" +
          "<request i:type=\"b:ExecuteWorkflowRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">" +
            "<a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">" +
              "<a:KeyValuePairOfstringanyType>" +
                "<c:key>EntityId</c:key>" +
                "<c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">" + entityId + "</c:value>" +
              "</a:KeyValuePairOfstringanyType>" +
              "<a:KeyValuePairOfstringanyType>" +
                "<c:key>WorkflowId</c:key>" +
                "<c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">" + 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, true)
        // Responses will return XML. It isn't possible to return JSON.
        req.setRequestHeader("Accept", "application/xml, text/xml, */*");
        req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
        req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
        req.onreadystatechange = function () { assignResponse(req); };
        req.send(request);


    }

    function assignResponse(req) {  
     if (req.readyState == 4) {
            if (req.status == 200) {
                alert('successfully executed the workflow');
            }
        }
    }

    Saturday, January 10, 2015 8:15 AM

All replies

  • Hi,

         Workflow will not be able to assign the output value for newly created record as output. But action can perform this. Have you tried to use Action instead of workflow to return the opportunity ID?


    Hope this helps.
     
    -----------------------------------------------------------------------
    Minal Dahiya
    blog : http://minaldahiya.blogspot.com.au/

     
    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    Saturday, January 10, 2015 8:54 AM
  • If I create an action then may I use this script just replacing the guid Id of action? 
    Saturday, January 10, 2015 9:10 AM
  • If I create an action then tell me how to execute through javascript in CRM 2013?
    Saturday, January 10, 2015 9:11 AM
  • Hi,

        Here is the article with code for how to call action from script.

    http://inogic.com/blog/2013/09/introduction-to-actions-in-crm-2013/


    Hope this helps.
     
    -----------------------------------------------------------------------
    Minal Dahiya
    blog : http://minaldahiya.blogspot.com.au/

     
    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    Saturday, January 10, 2015 10:08 AM