Hi Haritha,
If you have look at the code you will know where i have to make the corrections.
function CreateRecordInContact (executionContext) {
var formContext = executionContext.getFormContext();
var LName = formContext.getAttribute("name").getValue();
var AccountLookup = formContext.getAttribute("new_contactlookup").getValue();
var entity = {};
entity.lastname = LName;
entity["cr04d_accountlookup@odata.bind"] = AccountLookup;
// entity.creditonhold = null;
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/contacts", 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.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));
}