created Record data Using Web Api Request



var entity = {};
entity.new_currency = Number(parseFloat(13666).toFixed(4));
entity["new_customer_account@odata.bind"] = "/accounts(F62765A4-941A-E711-8117-C4346BDC5E51)";
entity.new_datetime = new Date("04/12/2017").toISOString();
entity.new_decimal = parseFloat(22.223).toFixed(2);
entity.new_floatpoint = parseFloat(2.3215).toFixed(2);
entity["new_lookuponaccountfromcontact@odata.bind"] = "/contacts(D9058775-01F0-E611-812C-5065F38C8781)";
entity.new_optionset = 1;
entity.new_twooptionset = false;
entity.new_wholenumber = null;
entity.accountnumber = "";

var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts", false);
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", "return=representation");
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 mtccup_calendarlineitemid = matches[1];
            calenderlineitem = mtccup_calendarlineitemid;
        }
        else {
            Xrm.Utility.alertDialog(this.status);
        }
    }
};
req.send(JSON.stringify(entity));

Comments

Popular posts from this blog

Basic Plugin Code in D365 using C#

CURD (Create, Update, Retrieve and Delete) Operation in D365 using Power Shell Script

Meta Data Using WebApiRequest