Error in the javascript using SOAP code. RRS feed

  • Question

  • The below code must work when we click on Ribbon button and data must be transfer to CRM to AX.

    I want this below code must run completely. plz resolve this problem.
    function transferdata()
      // alert("Test code");
         var accno = Xrm.Page.getAttribute("new_accountnumber").getValue();
        var customername = Xrm.Page.getAttribute("new_firstname").getValue();
         var custgroup=Xrm.Page.getAttribute("new_customergroup").getValue();
        // var email = Xrm.Page.getAttribute("new_email").getValue();     
         var  lookup=Xrm.Page.getAttribute("transactioncurrencyid");
         if(accno !=null && customername !=null &&  custgroup!=null && lookup !=null)
              var lookupobject=lookup.getValue();
              var Currency = lookupobject[0].name;
             var Currencycode = "INR";   
            alert("Account Number=" + accno + "\n\nFirst name=" + customername + "\n\nCustomerGroup=" +custgroup+ "\n\nCurrency="+Currencycode); 

     var xml ='<?xml version="1.0" encoding="utf-8"?>'+'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'+'<soap:Body>'+'<AxCreate xmlns="http://tempuri.org/">' +'<_Account>' + accno + '</_Account>' +'<_CustGroup>' + custgroup + '</_CustGroup>' +'<_Name>' + customername + '</_Name>' +'<_cur>' + Currencycode + '</_cur>' +'</AxCreate>' +'</soap:Body>' +'</soap:Envelope>';

        xmlHttp = new ActiveXObject('Msxml2.XMLHTTP'); 

        xmlHttp.open("POST", "", false, "administrator", "pass_12345");

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

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

        xmlHttp.setRequestHeader("SOAPAction", "http://tempuri.org/AxCreate");

        var resultXml = xmlHttp.responseXML;

          if (resultXml.text == 'Unable to connect to the remote server') 
            alert('Unable to connect to the remote server');

    Wednesday, October 8, 2014 2:38 PM

All replies

  • Dear Krishna,

    What error do you get during execution of this code? It would be complicated to help you out without understanding of error you experience.

    Also code new ActiveXObject('Msxml2.XMLHTTP'); would work fine only in IE. For other browsers it is recommended to use new XMLHttpRequest();

    Here is the cross-browser code for instantiation of XmlHttpRequest object instance:

    var xmlHttp = null;
    if (window.XMLHttpRequest) {
    	try {
    		xmlHttp = new XMLHttpRequest();
    	} catch (e){}
    } else if (window.ActiveXObject) {
    	try {
    		xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
            } catch (e){
    		try {
    			xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
    		} catch (e){}

    Dynamics CRM MVP/ Technical Evangelist at SlickData LLC
    My blog

    Wednesday, October 8, 2014 3:04 PM