Home > CRM 2011, JScript > Deleting a record using OData & JQuery in CRM 2011

Deleting a record using OData & JQuery in CRM 2011


Below is the script to delete record using OData & JScript


function deleteRecord(id, odataSetName) {

// Get Server URL

var serverUrl = Xrm.Page.context.getServerUrl();

//The OData end-point

var ODATA_ENDPOINT = “/XRMServices/2011/OrganizationData.svc”;

//Asynchronous AJAX function to Delete a CRM record using OData


type: “POST”,

contentType: “application/json; charset=utf-8”,

datatype: “json”,

url: serverUrl + ODATA_ENDPOINT + “/” + odataSetName + “(guid'” + id + “‘)”,

beforeSend: function (XMLHttpRequest) {

//Specifying this header ensures that the results will be returned as JSON.

XMLHttpRequest.setRequestHeader(“Accept”, “application/json”);

//Specify the HTTP method DELETE to perform a delete operation.

XMLHttpRequest.setRequestHeader(“X-HTTP-Method”, “DELETE”);


success: function (data, textStatus, XmlHttpRequest) {

alert(“Record deleted successfully!!!!”);


error: function (XmlHttpRequest, textStatus, errorThrown) {

alert(“Error while deletion – “+errorThrown);





How Do I call this method :-

    • To delete a “Account” record  set account id & Odata set name and call the above method

var accountId = {}; //Set Account GUID

var odataSeName = “AccountSet”;

deleteRecord(accountId, odataSeName);


Hope it helps 🙂

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: