Skip to main content

Delete record using JQuery and OData in Dynamics CRM 2011


function DeleteRecord(id, oDataSetName) {
    var serverUrl = Xrm.Page.context.getServerUrl();
    var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "(guid'" + id + "')",
        beforeSend: function (XMLHttpRequest) {
            //results will be returned as JSON. 
            XMLHttpRequest.setRequestHeader("Accept", "application/json");
            //HTTP method DELETE  
            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);
        }
    });
}

Comments

Popular posts from this blog

How to Integrate WhatsApp with Dynamics 365 Omnichannel – On Trial

How to Integrate WhatsApp with Dynamics 365 Omni Channel – On Trial Pre Requisites a.        Trail Environment with Customer Service Enabled, Preferably Netherlands as Location Ref : https://docs.microsoft.com/en-us/dynamics365/omnichannel/try-channels b.        Twilio Trial Account Ref : https://www.twilio.com/docs/usage/tutorials/how-to-use-your-free-trial-account#sign-up-for-your-free-twilio-trial Let’s Start the Configuration! Configuration: Dynamics 365 Channel Integration Framework - V2 1.        Go to dynamic 365 administration center via below link after logging to trial account https://port.crm4.dynamics.com/G/Applications/Index.aspx 2.        Make Sure Channel Integration Framework in Enabled, like in below screen shot else, configure it . By default, this should have enabled. Configuration: Omnichannel for Custo...

How to attach refresh event on Dynamic CRM 2011 subgrid using Java Script / JQuery ?

// Attach the function OnFormLoad event function OnFormLoad() {     setTimeout("SubGridRefresh();", 2500 ); } function   SubGridRefresh() {     var subgrid = document.getElementById("subgridid");     if (subgrid.readyState != "complete") {         // recursive till the subgrid is loaded         setTimeout(SubGridRefresh, 1000);         return;     }     // if subgrid fully loaded       if (subgrid) {         // attach the name of the custom function to grid          subgrid .attachEvent("onrefresh", OnRefresh_SubGrid);          subgrid .control.add_onRefresh(OnRefresh_SubGrid);     } } function   OnRefresh_SubGrid() {     //custom code to execute     var entityid = Xrm.Page.data.entity.getId();     alert(entityid); } ...