locked
using crm web service and javascipt to retrieve record in crm 2011 RRS feed

  • Question

  • Hi all,

     

    suppose the following code sample that run correctly in crm 4.0:

     

    // Prepare variables for a contact to retrieve.

    var accountid = crmForm.ObjectId;

    var authenticationHeader = GenerateAuthenticationHeader();

    alert(accountid);

    //// Prepare the SOAP message.

    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'>" +

    authenticationHeader +

    "<soap:Body>" +

    "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +

    "<entityName>account</entityName>" +

    "<id>" + accountid + "</id>" +

    "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>" +

    "<q1:Attributes>" +

    "<q1:Attribute>name</q1:Attribute>" +

    "</q1:Attributes>" +

    "</columnSet>" +

    "</Retrieve>" +

    "</soap:Body>" +

    "</soap:Envelope>";

    // Prepare the xmlHttpObject and send the request.

    var xHReq = new ActiveXObject("Msxml2.XMLHTTP");

    xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);

    xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");

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

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

    xHReq.send(xml);

    // Capture the result.

    var resultXml = xHReq.responseXML;

     

    // Check for errors.

    var errorCount = resultXml.selectNodes('//error').length;

    if (errorCount != 0)

    {

        var msg = resultXml.selectSingleNode('//description').nodeTypedValue;

        alert(msg);

    }

    // Display the retrieved value.

    else

    {

        alert(resultXml.selectSingleNode("//q1:name").nodeTypedValue);

    }

     

     

    could anybody please provide me with the equivalent code that works in crm 2011 on premise ??

     

    thanks in advance...

    Thursday, March 17, 2011 7:45 PM

Answers