This documentation is archived and is not being maintained.

CrmService.Retrieve Method Using JScript

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

This sample shows how to use the CrmService.Retrieve method using the example provided in the following topic: CrmService.Retrieve method.

To test this sample:

  1. Paste the following code into any Event Detail Properties dialog box.
  2. Save the form and then click Create Form on the Preview menu.


When the event occurs, the code will run. This sample uses the Retrieve method to return the fullname value for a specified contact. You must provide a valid contact ID.


// Prepare variables for a contact to retrieve.
var contactid = "4696f8cb-9a1c-dd11-ad3a-0003ff9ee217";
var authenticationHeader = GenerateAuthenticationHeader();

// Prepare the SOAP message.
var xml = "<?xml version='1.0' encoding='utf-8'?>"+ 
"<soap:Envelope xmlns:soap=''"+
" xmlns:xsi=''"+
" xmlns:xsd=''>"+ 
"<Retrieve xmlns=''>"+ 
"<columnSet xmlns:q1='' xsi:type='q1:ColumnSet'>"+ 
// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
// 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;
// Display the retrieved value.

The following is an example of a successful response:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="" xmlns:xsi="" xmlns:xsd="">
  <RetrieveResponse xmlns="">
   <RetrieveResult xmlns:q1="" xsi:type="q1:contact">
    <q1:fullname>Jesper Aaberg</q1:fullname>

© 2010 Microsoft Corporation. All rights reserved.