Tuesday, 25 December 2018

Update Records in CRM Using WEBAPI


/// Update Records in CRM Using WEBAPI
=====================================================================

function CreateRecords() {

    var entity = {};

    entity["new_Accounts@odata.bind"] = "/accounts(9083FB80-8844-E211-979C-00155D2EE30B)";
    entity.new_dob = new Date("12/20/2018").toISOString();
  //Whole number fields
    entity.new_numbers = 3333;
   //optionset field
    entity.new_countries = 3;
    //Currency field
    entity.new_moneytype = Number(parseFloat(444).toFixed(4));
    //two optionset field
    entity.new_gender = true
    //string field
    entity.new_name = "Test";
    //floating point numbers
    entity.new_rates = 44.55;
    var req = new XMLHttpRequest();
    req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/new_testcrms", true);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
    req.onreadystatechange = function () {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 204) {
                var uri = this.getResponseHeader("OData-EntityId");
                var regExp = /\(([^)]+)\)/;
                var matches = regExp.exec(uri);
                var newEntityId = matches[1];
            } else {
                Xrm.Utility.alertDialog(this.statusText);
            }
        }
    };
    req.send(JSON.stringify(entity));

}

No comments:

Post a Comment