Monday, 1 August 2016

Update record in crm 2016 using crm web api with java script

Retrieve record in CRM 2016 using CRM web API with java script.

Hello CRM Developers,
          Here is my new post, In this post I am going to to tell how to update record in dynamics CRM 2016 using CRM web API.

In new CRM 2016 release there is a new way introduced for operation like create, update, delete,retrieve, multiple retrieve etc, web API. Web API has been introduced so that communication between CRM and and other platform application can be done easily. New CRM web API is fully supports JSON format.

Below is the sample java script code for retrieving record in CRM using java script.

function update() {
    var clientURL = Xrm.Page.context.getClientUrl();
    var req = new XMLHttpRequest()
    var query = "/api/data/v8.0/accounts(5AC84B7C-4D57-E611-80DC-705A0F235AE3)";"PATCH", encodeURI(clientURL + query), true);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.onreadystatechange = function () {
        if (this.readyState == 4) {
            req.onreadystatechange = null;
            if (this.status == 204) {
            else {
                var error = JSON.parse(this.response).error;
                alert("Error deleting Account – " + error.message);

    //Create object of entity
    var account = new Object();
    //String Field = "Test Neo";
    //Option Set field
    account.ownershipcode = 1;
    //Two option
    account.donotemail = true;
    account.creditlimit = 12345;
    //Whole number
    account.numberofemployees = 28;
    account["primarycontactid@odata.bind"] = "/contacts(7166DE85-1858-E611-80DD-705A0F235AE3)"


For further help you can leave a comment.

Enjoy the great technology Dynamics CRM. Good Luck .....!!!!

Post a Comment