Advertisements
Home > CRM 2011, JScript > Delete record synchronously using OData and JScript in CRM 2011

Delete record synchronously using OData and JScript in CRM 2011

Hi,

Below is the script to delete record synchronously

function deleteRecordSync(recordId, odataSetName) {

// Get Server URL

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

//The OData end-point

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

var deleteRecordReq = new XMLHttpRequest();

var ODataPath = serverUrl + ODATA_ENDPOINT;

deleteRecordReq.open(‘POST’, ODataPath + “/” + odataSetName + “(guid'” + recordId + “‘)”, false);

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

deleteRecordReq.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);

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

deleteRecordReq.send(null);

}

How do I call this method :-

  • To delete an “Account”
  • Pass account GUID and OData Set name (i.e.,AccountSet)

Var accountId=”{Account GUID}”;

deleteRecordSync (accountId , “AccountSet”);

🙂

Advertisements
  1. Selva Antony
    April 2, 2013 at 3:44 PM

    thanks rajeev, its working fine 🙂

  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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: