none
CRM development RRS feed

  • Question

  • Hi everyone.

    I try to execute plug-in in dynamic CRM using Action and for achive to this I using WebResource and SOAP (XMLHttpRequest). But I getting an error (Internal Server Error each time). Can anyone help me to solve the issue?
    //Send request to FF for getting date befores using
    function transferRequest(TargetUrl) {//TargetUrl is a parameter for plug-in
        setTimeout(function () {
           var url = GetClientUrl();
            var requestName = "someActionName";//Action name
            var requestXML = "";      
            requestXML += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
            requestXML += "  <s:Body>";
            requestXML += "    <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
            requestXML += "      <request xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">";
            requestXML += "         <a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
            requestXML += "          <a:KeyValuePairOfstringanyType>";
            requestXML += "            <b:key>TargetUrl</b:key>";
            requestXML += "            <b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">" + TargetUrl + "</b:value>"; 
            requestXML += "          </a:KeyValuePairOfstringanyType>";
            requestXML += "        </a:Parameters>";
            requestXML += "        <a:RequestId i:nil=\"true\">";
            requestXML += "        </a:RequestId>";
            requestXML += "        <a:RequestName>" + requestName + "</a:RequestName>";
            requestXML += "      </request>";
            requestXML += "    </Execute>";
            requestXML += "  </s:Body>";
            requestXML += "</s:Envelope>";
    
            var req = new XMLHttpRequest();
            req.open("POST", url, false);
            req.setRequestHeader("Accept", "application/xml, text/xml, */*"); //TODO: delete
            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 () {
                if (this.readyState == XMLHttpRequest.DONE && this.status == 200) {
                    console.info("Ready State: Done (code: " + this.readyState + ")\n" + "Status: " + this.status + "\nResponse Text: " +  this.responseText);
                    //assignResponse(req);
                } else {
                    console.info("Ready State: Fault (code: " + this.readyState + ")\n" + "Status: " + this.status + "\nResponse Text: " +  this.responseText);
                    //assignResponse(req);
                }
            };
    
            try {
                req.send(requestXML);
            }
            catch (e) {
                alert("Request Send Error: " + e.message + "\n" + e.description);
            }
        }, 100);
    }
    
    //get client url for SOAP request
    function GetClientUrl() {
        if (typeof Xrm.Page.context == "object") {
            clientUrl = Xrm.Page.context.getClientUrl();
        }
        var ServicePath = "/XRMServices/2011/Organization.svc/web";
        return clientUrl + ServicePath;
    }
    
    Action which already created and activated.


    Regards Edgar Tadevosyan


    • Edited by Edgar Tadevosyan Wednesday, July 11, 2018 6:58 AM
    • Moved by ЖукMVP Thursday, June 27, 2019 4:35 PM Более подходящий раздел
    Wednesday, July 11, 2018 6:57 AM