I am creating an Opportunity using the new Web API REST endpoint and I have the following code to do so
var entity = {};
entity.name = "ABCD";
entity.customerid = {
Id: "CC7CC89D-3A4D-4BA1-9255-5DC2A92856DB",
LogicalName: "account"
};
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/opportunities", 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 {
alert(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
My problem is I can't include a lookup field in the create, every time I do so, I am getting an error.
What is the correct format to include a lookup field in create?
Thanks a million!!