locked
Retrieve Account with Javascript SOAP RRS feed

  • Question

  • Hi, I need help setting up an xml file to retrieve data from the Account entity via SOAP /Javascript / CRM 2011. Want to get the address of a customer searching for your ID.
    The code that does not bug ridden, but returns no data. Below is the code I'm using:

    ----------------------------------------------------------------------------------------------------------------------------------

    function getAccount() {

     var customerid = "8C07672C-3644-E011-8722-1CC1DEE87ACD";
     var address = getAdressAccount("account","accountid","address1_line1",customerid);
     alert(address);
    }


    function getAdressAccount (sEntityName, sFilterAttribute,sEntityGuidAttribute, sLookupValue)
    {
        var xml = "" +       
        "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" +           
        " <soap:Body>" +
        "<RetrieveMultiple xmlns='http://schemas.microsoft.com/xrm/2011/Contracts/Services' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> "+   
        "<query xsi:type='q1:QueryExpression' xmlns:q1='http://schemas.microsoft.com/xrm/2011/Contracts'>" +           
        " <q1:EntityName>" + sEntityName + "</q1:EntityName>" +
        " <q1:ColumnSet xsi:type=\"q1:AllColumns\" />" +
        " <q1:Distinct>false</q1:Distinct>" +
        " <q1:Criteria>" +
        " <q1:FilterOperator>And</q1:FilterOperator>" +
        " <q1:Conditions>" +
        " <q1:Condition>" +
        " <q1:AttributeName>" + sFilterAttribute + "</q1:AttributeName>" +
        " <q1:Operator>Equal</q1:Operator>" +
        " <q1:Values>" +
        " <q1:Value xsi:type=\"c:string\">" + sLookupValue + "</q1:Value>" +
        " </q1:Values>" +
        " </q1:Condition>" +
        " </q1:Conditions>" +
        " </q1:Criteria>" +
        " </query>" +
        " </soap:Body>" +
        "</soap:Envelope>";

        var req = new ActiveXObject ("Msxml2.XMLHTTP");   
        req.open("POST", _getServerUrl(), true);    
        req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/RetrieveMultiple")
        req.setRequestHeader ("Content-Type", "text/xml; charset=utf-8");
        req.setRequestHeader ("Content-Length", xml.length);
        req.send (xml);

        var resultXML = req.responseXml;

        // Check for errors.
        var errorCount = resultXML.selectNodes ('//error').length;
        if (errorCount != 0) {
        var msg = resultXML.selectSingleNode ('//description').nodeTypedValue;
        return "-1";
        }
        var nodeList = resultXML.selectNodes ("//BusinessEntity")
        var result = "";

        for(i = 0; i < nodeList.length; i++) {  
        result = nodeList[i].selectSingleNode ("./q1:" + sEntityGuidAttribute).text;
        }
        return result;
    }

    ----------------------------------------------------------------------------------------------------------------------------------

    Does anyone know what's wrong?

    thanks
    William

    Sunday, March 20, 2011 3:15 PM

All replies

  • replace

      var req = new ActiveXObject ("Msxml2.XMLHTTP");  
      req.open("POST", _getServerUrl(), true);   
      req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/RetrieveMultiple")
      req.setRequestHeader ("Content-Type", "text/xml; charset=utf-8");
      req.setRequestHeader ("Content-Length", xml.length);
      req.send (xml);
    
    
    

    with:

      var req = new ActiveXObject ("Msxml2.XMLHTTP");  
      req.open("POST", "/mscrmservices/2007/CrmService.asmx", false);   
      req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/RetrieveMultiple")
      req.setRequestHeader ("Content-Type", "text/xml; charset=utf-8");
      req.setRequestHeader ("Content-Length", xml.length);
      req.send (xml);
    
    
    

    http://mscrmblog.net
    Microsoft Certified Business Management Solutions Specialist
    Microsoft Certified CRM Developer
    Tuesday, March 22, 2011 6:26 AM
  • I would say for the 2nd line:

    req.open("POST", "/XRMServices/2011/Organization.svc/web", false);


    feel the code
    • Proposed as answer by MRashwan Monday, April 4, 2011 12:28 PM
    Monday, April 4, 2011 12:18 PM
  • If you're still having issues, it looks like you've combined the CRM 4.0 SOAP with the CRM 2011 SOAP.

     

    You can still use the 4.0 endpoint, but you have to be consistent.

    Wednesday, April 13, 2011 10:31 PM