I have an entity "Customer Asset" which has relation with another entity "External Project". The field of the external project is Lookup in the customer asset entity. When trying to create a new record in customer asset entity using CRM REST Builder. I got no response and the record is not created. But when i remove the external project from the added attributes the record is created successfully. i don't know where is the problem!
The API:
var entity = {};
entity.msdyn_name = "Asset test";
entity.new_assetcode = " 56587";
entity["new_externalproject@odata.bind"] = "/msdynce_externalprojects(xxx)";
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/msdyn_customerassets", 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));