This documentation is archived and is not being maintained.

CrmService.Delete 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.Delete method using the same example provided in the Server Programming Guide: CrmService.Delete 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 code deletes an existing contact record. You must provide a valid contact ID value to test this sample.


// Identify the contact to delete.
var contactid = "57a4e111-7027-dd11-b452-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=''>"+ 
"<Delete xmlns=''>"+ 
// 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 confirmation message.
alert("Contact with id = "+contactid+" successfully deleted");

A successful response includes XML that returns a DeleteResponse. The following is an example of a successful response:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="" xmlns:xsi="" xmlns:xsd="">
  <DeleteResponse xmlns="" />

© 2010 Microsoft Corporation. All rights reserved.